xref: /qemu/tests/qtest/hexloader-test.c (revision 66997c42)
11e8a1faeSThomas Huth /*
21e8a1faeSThomas Huth  * QTest testcase for the Intel Hexadecimal Object File Loader
31e8a1faeSThomas Huth  *
41e8a1faeSThomas Huth  * Authors:
51e8a1faeSThomas Huth  *  Su Hang <suhang16@mails.ucas.ac.cn> 2018
61e8a1faeSThomas Huth  *
71e8a1faeSThomas Huth  * This work is licensed under the terms of the GNU GPL, version 2 or later.
81e8a1faeSThomas Huth  * See the COPYING file in the top-level directory.
91e8a1faeSThomas Huth  *
101e8a1faeSThomas Huth  */
111e8a1faeSThomas Huth 
121e8a1faeSThomas Huth #include "qemu/osdep.h"
13907b5105SMarc-André Lureau #include "libqtest.h"
141e8a1faeSThomas Huth 
151e8a1faeSThomas Huth /* Load 'test.hex' and verify that the in-memory contents are as expected.
161e8a1faeSThomas Huth  * 'test.hex' is a memory test pattern stored in Hexadecimal Object
171e8a1faeSThomas Huth  * format.  It loads at 0x10000 in RAM and contains values from 0 through
181e8a1faeSThomas Huth  * 255.
191e8a1faeSThomas Huth  */
hex_loader_test(void)201e8a1faeSThomas Huth static void hex_loader_test(void)
211e8a1faeSThomas Huth {
221e8a1faeSThomas Huth     unsigned int i;
231e8a1faeSThomas Huth     const unsigned int base_addr = 0x00010000;
241e8a1faeSThomas Huth 
251e8a1faeSThomas Huth     QTestState *s = qtest_initf(
261e8a1faeSThomas Huth         "-M vexpress-a9 -device loader,file=tests/data/hex-loader/test.hex");
271e8a1faeSThomas Huth 
281e8a1faeSThomas Huth     for (i = 0; i < 256; ++i) {
291e8a1faeSThomas Huth         uint8_t val = qtest_readb(s, base_addr + i);
301e8a1faeSThomas Huth         g_assert_cmpuint(i, ==, val);
311e8a1faeSThomas Huth     }
321e8a1faeSThomas Huth     qtest_quit(s);
331e8a1faeSThomas Huth }
341e8a1faeSThomas Huth 
main(int argc,char ** argv)351e8a1faeSThomas Huth int main(int argc, char **argv)
361e8a1faeSThomas Huth {
371e8a1faeSThomas Huth     g_test_init(&argc, &argv, NULL);
381e8a1faeSThomas Huth 
391e8a1faeSThomas Huth     qtest_add_func("/tmp/hex_loader", hex_loader_test);
4066997c42SMarkus Armbruster     return g_test_run();
411e8a1faeSThomas Huth }
42