FSMaxB / mcJSON

A fork of cJSON with the goal of making it fit to create JSON containing cryptographic keys.
ISC License
2 stars 1 forks source link

Test fails on RaspberryPi 2 #8

Closed FSMaxB closed 8 years ago

FSMaxB commented 8 years ago

The tests fail on the RaspberryPi 2.

Tests

$ make test
Running tests...
Test project /home/max/mcJSON/build
      Start  1: test-objects
 1/26 Test  #1: test-objects ......................   Passed    0.01 sec
      Start  2: test-objects-valgrind
 2/26 Test  #2: test-objects-valgrind .............   Passed    2.74 sec
      Start  3: test-objects-comparison
 3/26 Test  #3: test-objects-comparison ...........   Passed    0.02 sec
      Start  4: test-utils
 4/26 Test  #4: test-utils ........................   Passed    0.01 sec
      Start  5: test-utils-valgrind
 5/26 Test  #5: test-utils-valgrind ...............   Passed    2.51 sec
      Start  6: test_utils-comparison
 6/26 Test  #6: test_utils-comparison .............   Passed    0.02 sec
      Start  7: test-file-test1.json
 7/26 Test  #7: test-file-test1.json ..............   Passed    0.01 sec
      Start  8: test-file-test1.json-valgrind
 8/26 Test  #8: test-file-test1.json-valgrind .....   Passed    2.18 sec
      Start  9: test-file-test1.json-comparison
 9/26 Test  #9: test-file-test1.json-comparison ...   Passed    0.02 sec
      Start 10: test-file-test2.json
10/26 Test #10: test-file-test2.json ..............   Passed    0.01 sec
      Start 11: test-file-test2.json-valgrind
11/26 Test #11: test-file-test2.json-valgrind .....   Passed    2.17 sec
      Start 12: test-file-test2.json-comparison
12/26 Test #12: test-file-test2.json-comparison ...   Passed    0.02 sec
      Start 13: test-file-test3.json
13/26 Test #13: test-file-test3.json ..............   Passed    0.01 sec
      Start 14: test-file-test3.json-valgrind
14/26 Test #14: test-file-test3.json-valgrind .....   Passed    2.23 sec
      Start 15: test-file-test3.json-comparison
15/26 Test #15: test-file-test3.json-comparison ...   Passed    0.02 sec
      Start 16: test-file-test4.json
16/26 Test #16: test-file-test4.json ..............   Passed    0.01 sec
      Start 17: test-file-test4.json-valgrind
17/26 Test #17: test-file-test4.json-valgrind .....   Passed    2.33 sec
      Start 18: test-file-test4.json-comparison
18/26 Test #18: test-file-test4.json-comparison ...   Passed    0.02 sec
      Start 19: test-file-test5.json
19/26 Test #19: test-file-test5.json ..............   Passed    0.01 sec
      Start 20: test-file-test5.json-valgrind
20/26 Test #20: test-file-test5.json-valgrind .....   Passed    2.20 sec
      Start 21: test-file-test5.json-comparison
21/26 Test #21: test-file-test5.json-comparison ...   Passed    0.02 sec
      Start 22: test-buffered-parse
22/26 Test #22: test-buffered-parse ...............***Exception: SegFault  0.10 sec
      Start 23: test-buffered-parse-valgrind
23/26 Test #23: test-buffered-parse-valgrind ......***Exception: SegFault  2.41 sec
      Start 24: test-buffered-parse-comparison
24/26 Test #24: test-buffered-parse-comparison ....***Failed    0.03 sec
      Start 25: buffer-test
25/26 Test #25: buffer-test .......................   Passed    0.01 sec
      Start 26: buffer-test-valgrind
26/26 Test #26: buffer-test-valgrind ..............   Passed    2.11 sec

88% tests passed, 3 tests failed out of 26

Total Test time (real) =  21.33 sec

The following tests FAILED:
     22 - test-buffered-parse (SEGFAULT)
     23 - test-buffered-parse-valgrind (SEGFAULT)
     24 - test-buffered-parse-comparison (Failed)
Errors while running CTest
Makefile:61: recipe for target 'test' failed
make: *** [test] Error 8

test-buffered-parse

$ valgrind --leak-check=full ./test-buffered-parse
==4474== Memcheck, a memory error detector
==4474== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==4474== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==4474== Command: ./test-buffered-parse
==4474== 
==4474== 
==4474== Process terminating with default action of signal 7 (SIGBUS)
==4474==  Invalid address alignment at address 0x4AB31DE
==4474==    at 0x11D50: parse_number (mcJSON.c:127)
==4474==    by 0x12B07: parse_value (mcJSON.c:701)
==4474==    by 0x12D07: parse_object (mcJSON.c:1072)
==4474==    by 0x12B3F: parse_value (mcJSON.c:707)
==4474==    by 0x12D07: parse_object (mcJSON.c:1072)
==4474==    by 0x12B3F: parse_value (mcJSON.c:707)
==4474==    by 0x144B3: mcJSON_ParseWithBuffer (mcJSON.c:625)
==4474==    by 0x14527: mcJSON_ParseBuffered (mcJSON.c:643)
==4474==    by 0x11AF7: main (test-buffered-parse.c:91)
==4474== 
==4474== HEAP SUMMARY:
==4474==     in use at exit: 4,020 bytes in 2 blocks
==4474==   total heap usage: 2 allocs, 0 frees, 4,020 bytes allocated
==4474== 
==4474== LEAK SUMMARY:
==4474==    definitely lost: 0 bytes in 0 blocks
==4474==    indirectly lost: 0 bytes in 0 blocks
==4474==      possibly lost: 0 bytes in 0 blocks
==4474==    still reachable: 4,020 bytes in 2 blocks
==4474==         suppressed: 0 bytes in 0 blocks
==4474== Reachable blocks (those to which a pointer was found) are not shown.
==4474== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==4474== 
==4474== For counts of detected and suppressed errors, rerun with: -v
==4474== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Bus error (core dumped)
FSMaxB commented 8 years ago

I found the reason why this happened: The ARM processor in the RaspberryPi 2 requires data types to be aligned before performing instructions on them, but my manual allocator that allocates everything in one buffer didn't do this alignment, so some instances of the mcJSON struct weren't aligned properly and the program crashes on access.