Branch data Line data Source code
1 : : #include "test_libmem_all.h"
2 : :
3 : : /**
4 : : * @brief Verify that a process-wide global_return_status of INFO flows
5 : : * through libmem resizes without skipping internal run() bookkeeping
6 : : *
7 : : * Sets global_return_status to INFO, performs an m_resize-driven shrink
8 : : * of a string descriptor, then restores the global status. The test
9 : : * asserts that the resize return carries TRIUMPH and INFO, that HALTED
10 : : * does not leak in, and that the descriptor actually shrank to the new
11 : : * visible length. The Telemetry struct is used as a drift detector: if
12 : : * any internal run(...) step inside m_resize had been silently skipped
13 : : * because of the INFO flag, the current_* counters would not return to
14 : : * baseline after m_del. So this test is about how a process-wide global
15 : : * status propagates through libmem operations, not about telemetry
16 : : * itself
17 : : *
18 : : * @return Return describing success or failure
19 : : */
20 : 1 : Return test_libmem_0071(void)
21 : : {
22 : 1 : INITTEST;
23 : :
24 : 1 : const size_t baseline_heap_bytes = telemetry.current_heap_reserved_bytes;
25 : 1 : const size_t baseline_payload_bytes = telemetry.current_payload_bytes;
26 : 1 : const size_t baseline_block_overhead_bytes = telemetry.current_block_overhead_bytes;
27 : 1 : const size_t baseline_current_active_descriptors = telemetry.current_active_descriptors;
28 : :
29 : 1 : const size_t initial_elements = sizeof("graceful////");
30 : 1 : const size_t shrunken_elements = sizeof("graceful");
31 : 1 : const size_t expected_heap_drift = MEMORY_BLOCK_BYTES;
32 : :
33 : 1 : m_create(char,graceful_path,MEMORY_STRING);
34 : :
35 : 1 : ASSERT(SUCCESS == m_copy_literal(graceful_path,"graceful////"));
36 : 1 : ASSERT(telemetry.current_heap_reserved_bytes == baseline_heap_bytes + expected_heap_drift);
37 : 1 : ASSERT(telemetry.current_payload_bytes == baseline_payload_bytes + initial_elements);
38 : 1 : ASSERT(telemetry.current_block_overhead_bytes ==
39 : : baseline_block_overhead_bytes + expected_heap_drift - initial_elements);
40 : 1 : ASSERT(telemetry.current_active_descriptors == baseline_current_active_descriptors + 1U);
41 : :
42 : 1 : IF(SUCCESS == status)
43 : : {
44 : 1 : Return saved_global_status = atomic_exchange(&global_return_status,INFO);
45 : 1 : Return resize_status = m_resize(graceful_path,shrunken_elements);
46 : 1 : atomic_store(&global_return_status,saved_global_status);
47 : :
48 : 1 : ASSERT(TRIUMPH & resize_status);
49 : 1 : ASSERT(INFO & resize_status);
50 : 1 : ASSERT((HALTED & resize_status) == 0);
51 : : }
52 : :
53 : 1 : ASSERT(graceful_path->length == shrunken_elements);
54 : 1 : ASSERT(graceful_path->string_length == shrunken_elements - 1U);
55 : 1 : ASSERT(0 == strcmp(m_text(graceful_path),"graceful"));
56 : 1 : ASSERT(telemetry.current_heap_reserved_bytes == baseline_heap_bytes + expected_heap_drift);
57 : 1 : ASSERT(telemetry.current_payload_bytes == baseline_payload_bytes + shrunken_elements);
58 : 1 : ASSERT(telemetry.current_block_overhead_bytes ==
59 : : baseline_block_overhead_bytes + expected_heap_drift - shrunken_elements);
60 : 1 : ASSERT(telemetry.current_active_descriptors == baseline_current_active_descriptors + 1U);
61 : :
62 : 1 : call(m_del(graceful_path));
63 : :
64 : 1 : ASSERT(telemetry.current_heap_reserved_bytes == baseline_heap_bytes);
65 : 1 : ASSERT(telemetry.current_payload_bytes == baseline_payload_bytes);
66 : 1 : ASSERT(telemetry.current_block_overhead_bytes == baseline_block_overhead_bytes);
67 : 1 : ASSERT(telemetry.current_active_descriptors == baseline_current_active_descriptors);
68 : :
69 : 1 : RETURN_STATUS;
70 : : }
|