Skip to content

Commit 23c3670

Browse files
author
James Foster
committed
The test is now more explicit about looking at the values expected. Before the fix to Client.h we get the following error:
``` # Subtest: Client_copy_constructor ok 1 - assertEqual "1" == *(c1.mGodmodeDataIn) ok 2 - assertEqual "2" == *(c2.mGodmodeDataIn) not ok 3 - assertNotEqual c1.mGodmodeDataIn != c2.mGodmodeDataIn --- operator: != unwanted: 0x603000007750 actual: 0x603000007750 at: file: /Users/jfoster/Documents/Arduino/libraries/TestSomething/test/clientServer.cpp line: 32 ... ok 4 - assertEqual "1" == *(c1.mGodmodeDataIn) ok 5 - assertEqual "1" == *(c2.mGodmodeDataIn) not ok 6 - assertEqual "11" == *(c1.mGodmodeDataIn) --- operator: == expected: 11 actual: 112 at: file: /Users/jfoster/Documents/Arduino/libraries/TestSomething/test/clientServer.cpp line: 37 ... not ok 7 - assertEqual "12" == *(c2.mGodmodeDataIn) --- operator: == expected: 12 actual: 112 at: file: /Users/jfoster/Documents/Arduino/libraries/TestSomething/test/clientServer.cpp line: 38 ... AddressSanitizer:DEADLYSIGNAL ================================================================= ==16588==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x0001076e5918 bp 0x7ffee8564290 sp 0x7ffee8564260 T0) ==16588==The signal is caused by a READ memory access. ==16588==Hint: this fault was caused by a dereference of a high value address (see register values below). Dissassemble the provided pc to learn which register was used. #0 0x1076e5918 in __asan::Allocator::Deallocate(void*, unsigned long, unsigned long, __sanitizer::BufferedStackTrace*, __asan::AllocType)+0x48 (libclang_rt.asan_osx_dynamic.dylib:x86_64+0x5918) #1 0x107733125 in wrap__ZdlPv+0xe5 (libclang_rt.asan_osx_dynamic.dylib:x86_64+0x53125) #2 0x10769d528 in String::~String() WString.h:65 #3 0x10769d228 in String::~String() WString.h:65 #4 0x1076a6856 in Client::~Client() Client.h:35 #5 0x1076a2f48 in Client::~Client() Client.h:33 #6 0x1076a3473 in test_Client_copy_constructor::task() clientServer.cpp:39 #7 0x1076a8390 in Test::test() ArduinoUnitTests.h:205 #8 0x1076a7f2d in Test::run(Test::ReporterTAP*) ArduinoUnitTests.h:176 #9 0x1076a5713 in Test::run_and_report(int, char**) ArduinoUnitTests.h:195 #10 0x1076a5658 in main clientServer.cpp:110 #11 0x7fff70a26cc8 in start+0x0 (libdyld.dylib:x86_64+0x1acc8) ==16588==Register values: rax = 0x0000000000000002 rbx = 0xbebebebebebebebe rcx = 0x0000000000000003 rdx = 0x0000000000000000 rdi = 0xbebebebebebebebe rsi = 0xbebebebebebebebe rbp = 0x00007ffee8564290 rsp = 0x00007ffee8564260 r8 = 0x00007ffee85642a0 r9 = 0x0000000000000002 r10 = 0xffffffffffffffff r11 = 0x00000fffffffffff r12 = 0x0000000000000002 r13 = 0x0000000000000000 r14 = 0x00007ffee85642a0 r15 = 0x0000000107780d40 AddressSanitizer can not provide additional info. SUMMARY: AddressSanitizer: SEGV (libclang_rt.asan_osx_dynamic.dylib:x86_64+0x5918) in __asan::Allocator::Deallocate(void*, unsigned long, unsigned long, __sanitizer::BufferedStackTrace*, __asan::AllocType)+0x48 ==16588==ABORTING ...Unit testing clientServer.cpp with g++ for uno ✗ ``` After the fix we get the following: ``` # Subtest: Client_copy_constructor ok 1 - assertEqual "1" == *(c1.mGodmodeDataIn) ok 2 - assertEqual "2" == *(c2.mGodmodeDataIn) ok 3 - assertNotEqual c1.mGodmodeDataIn != c2.mGodmodeDataIn ok 4 - assertEqual "1" == *(c1.mGodmodeDataIn) ok 5 - assertEqual "1" == *(c2.mGodmodeDataIn) ok 6 - assertEqual "11" == *(c1.mGodmodeDataIn) ok 7 - assertEqual "12" == *(c2.mGodmodeDataIn) ok 8 - True true 1..8 ok 2 - Client_copy_constructor ```
1 parent 2b7c6e3 commit 23c3670

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

SampleProjects/TestSomething/test/clientServer.cpp

+20-7
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,26 @@ unittest(Client) {
2020
}
2121

2222
unittest(Client_copy_constructor) {
23-
{ // Client object contains a reference to a String object
24-
Client c1; // Constructor instantiates a String (s1)
25-
Client c2; // Constructor instantiates a String (s2)
26-
c2 = c1; // Does c2 get a reference to s1 or a copy of it?
27-
} // End of scope calls destructor on c1 and c2
28-
assertTrue(true); // Was s1 deleted once (with c1) or twice (also with c2)?
29-
// Was s2 deleted at all (should be during assignment)?
23+
{ // Client object contains a reference to a String object
24+
Client c1; // Constructor instantiates a String (string1)
25+
Client c2; // Constructor instantiates a String (string2)
26+
c1.write('1');
27+
c2.write('2');
28+
assertEqual("1", *(c1.mGodmodeDataIn));
29+
assertEqual("2", *(c2.mGodmodeDataIn));
30+
c2 = c1; // c2 should get a copy of s1, not a reference to it
31+
// and string2 should have been deleted during the assignment
32+
assertNotEqual(c1.mGodmodeDataIn, c2.mGodmodeDataIn);
33+
assertEqual("1", *(c1.mGodmodeDataIn));
34+
assertEqual("1", *(c2.mGodmodeDataIn));
35+
c1.write('1');
36+
c2.write('2');
37+
assertEqual("11", *(c1.mGodmodeDataIn));
38+
assertEqual("12", *(c2.mGodmodeDataIn));
39+
} // End of scope calls destructor on c1 and c2
40+
// Memory monitoring will give an error if delete is called twice on string1
41+
// The following assertion is just to confirm that we got through the above
42+
assertTrue(true);
3043
}
3144

3245
unittest(IPAddress) {

0 commit comments

Comments
 (0)