Changeset 6f7aff3 for tests/collections
- Timestamp:
- Oct 19, 2021, 10:31:53 AM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
- Children:
- fe18b46
- Parents:
- 7b0e8b7
- Location:
- tests/collections
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/collections/string-api-coverage.cfa
r7b0e8b7 r6f7aff3 1 1 #include <containers/string.hfa> 2 #include <string_sharectx.hfa> 2 3 3 4 void assertWellFormedHandleList( int maxLen ) { // with(HeapArea) … … 25 26 26 27 int main () { 28 29 #ifdef STRING_SHARING_OFF 30 sout | "string sharing disabled"; 31 string_sharectx c = { NO_SHARING }; 32 #endif 33 27 34 string s = "hello"; 28 35 string s2 = "hello"; -
tests/collections/string-ctx-manage.cfa
r7b0e8b7 r6f7aff3 3 3 #include <string_res.hfa> 4 4 5 // In these tests, shared heaps are never remotely full and string sizes are tiny. 6 // So here, the SUT should put a yes-sharing string in a heap with lots of spare room. 7 // The SUT should always keep a no-sharing string's buffer 1x--2x the string's size. 8 // This check uses 3x as a heuristic split between those cases. 9 void assertSpareRoomInHeap( string & s, bool expectOversized ) { 10 double bytesInHeap = DEBUG_string_bytes_in_heap(s.inner->Handle.ulink); 11 double bytesUsed = s.inner->Handle.lnth; 12 double overhead = bytesInHeap / bytesUsed; 13 assert (overhead >= 1); 14 if ( expectOversized ) 15 assert( overhead >= 3.0 ); 16 else 17 assert( overhead < 3.0 ); 18 } 19 5 20 void baseline() { 6 21 string x = "hi"; 22 assertSpareRoomInHeap( x, true ); 7 23 8 24 string y = x; // construct y in same context, no write yet => no copy yet 25 assertSpareRoomInHeap( y, true ); 9 26 assert( y.inner->Handle.s == x.inner->Handle.s); 10 27 sout | y; // hi 11 28 12 29 x = "bye"; 30 assertSpareRoomInHeap( x, true ); 13 31 y = x; // y in same context, no write yet => no copy yet 32 assertSpareRoomInHeap( y, true ); 14 33 assert( y.inner->Handle.s == x.inner->Handle.s); 15 34 sout | y; // bye … … 18 37 void eagerCopy() { 19 38 string x = "hi"; 39 assertSpareRoomInHeap( x, true ); 20 40 string_sharectx c = { NEW_SHARING }; 21 41 22 42 string y = x; // construct y in different context => eager copy 43 assertSpareRoomInHeap( y, true ); 23 44 assert( y.inner->Handle.s != x.inner->Handle.s); 24 45 sout | y; // hi 25 46 26 47 x = "bye"; 48 assertSpareRoomInHeap( x, true ); 27 49 y = x; // y was already in different context => eager copy 50 assertSpareRoomInHeap( y, true ); 28 51 assert( y.inner->Handle.s != x.inner->Handle.s); 29 52 sout | y; // bye … … 32 55 void soloAlloc() { 33 56 string x = "hi"; 57 assertSpareRoomInHeap( x, true ); 34 58 string_sharectx c = { NO_SHARING }; 35 59 36 60 string y = x; // y allocates into private pad, implying eager copy 61 assertSpareRoomInHeap( y, false ); 37 62 assert( y.inner->Handle.s != x.inner->Handle.s); 38 assert( DEBUG_string_bytes_in_heap(y.inner->Handle.ulink) == y.inner->Handle.lnth ); // y is in a perfectly fitting heap39 63 sout | y; // hi 40 64 41 65 x = "bye"; 66 assertSpareRoomInHeap( x, true ); 42 67 y = x; // into private y => eager copy 68 assertSpareRoomInHeap( y, false ); 43 69 assert( y.inner->Handle.s != x.inner->Handle.s); 44 // assert( DEBUG_string_bytes_in_heap(y.inner->Handle.ulink) == y.inner->Handle.lnth ); // optimization required45 70 sout | y; // bye 46 71 }
Note: See TracChangeset
for help on using the changeset viewer.