Branch data Line data Source code
1 : : #include "test_libmem_all.h"
2 : :
3 : : /**
4 : : * @brief Capture the negative resize case for a descriptor with a broken string cache
5 : : *
6 : : * @return Return describing success or failure
7 : : */
8 : 1 : static Return capture_libmem_inconsistent_resize_string_cache(void)
9 : : {
10 : 1 : INITTEST;
11 : :
12 : 1 : char materialized_string[] = "alpha";
13 : 1 : memory invalid_string = m_init(char,MEMORY_STRING);
14 : :
15 : 1 : invalid_string.data = materialized_string;
16 : 1 : invalid_string.length = sizeof(materialized_string);
17 : 1 : invalid_string.actually_allocated_bytes = sizeof(materialized_string);
18 : 1 : invalid_string.string_length = sizeof(materialized_string);
19 : 1 : invalid_string.is_string = true;
20 : :
21 : 1 : ASSERT(FAILURE == m_resize(&invalid_string,sizeof(materialized_string) + 2));
22 : 1 : ASSERT(invalid_string.data == materialized_string);
23 : 1 : ASSERT(invalid_string.length == sizeof(materialized_string));
24 : 1 : ASSERT(invalid_string.string_length == sizeof(materialized_string));
25 : 1 : ASSERT(invalid_string.is_string == true);
26 : :
27 : 1 : deliver(status);
28 : : }
29 : :
30 : : /**
31 : : * @brief Check resize rejection for descriptors with an inconsistent cached string length
32 : : *
33 : : * @return Return describing success or failure
34 : : */
35 : 1 : Return test_libmem_0038(void)
36 : : {
37 : 1 : INITTEST;
38 : :
39 : : /* Expected stderr layout for the inconsistent cached-length resize
40 : : rejection. The source line number and errno wording are intentionally
41 : : flexible because they are build- and platform-dependent */
42 : : static const char expected_stderr_pattern_libmem_0038[] =
43 : : "\\A"
44 : : "ERROR: src/mem_resize\\.c:mem_resize:\\d+ Memory management; String descriptor cache is inconsistent during resize Errno: [^\\n]+ \\(errno: [0-9]+\\)\n"
45 : : "\\Z";
46 : :
47 : 1 : ASSERT(SUCCESS == match_function_output(NULL,expected_stderr_pattern_libmem_0038,capture_libmem_inconsistent_resize_string_cache));
48 : :
49 : 1 : RETURN_STATUS;
50 : : }
|