File tree 7 files changed +86
-2
lines changed
7 files changed +86
-2
lines changed Original file line number Diff line number Diff line change 39
39
/tests /test_alternatively_push_and_pop_one_frame_messages_with_jump
40
40
/tests /test_cons_pops_buffer_start
41
41
/tests /test_cons_reaches_queue_end
42
+ /tests /test_error_str
42
43
/tests /test_fork
43
44
/tests /test_main
44
45
/tests /test_prod_jumps_to_buffer_start_and_pushes_too_long_message
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ TESTS = \
12
12
tests/test_alternatively_push_and_pop_one_frame_messages_with_jump \
13
13
tests/test_cons_pops_buffer_start \
14
14
tests/test_cons_reaches_queue_end \
15
+ tests/test_error_str \
15
16
tests/test_fork \
16
17
tests/test_main \
17
18
tests/test_prod_jumps_to_buffer_start_and_pushes_too_long_message \
@@ -47,6 +48,10 @@ tests_test_cons_reaches_queue_end_SOURCES = \
47
48
$(libshmemq_a_SOURCES ) \
48
49
tests/test_cons_reaches_queue_end.c
49
50
51
+ tests_test_error_str_SOURCES = \
52
+ $(libshmemq_a_SOURCES ) \
53
+ tests/test_error_str.c
54
+
50
55
tests_test_fork_SOURCES = \
51
56
$(libshmemq_a_SOURCES ) \
52
57
tests/test_fork.c
Original file line number Diff line number Diff line change @@ -69,7 +69,11 @@ int main()
69
69
shmemq_pop_end (shmemq , & shmemq_error );
70
70
71
71
if (shmemq_error != SHMEMQ_ERROR_NONE ) {
72
- printf ("Error: %u.\n" , shmemq_error );
72
+ printf (
73
+ "Error: %u (SHMEMQ_ERROR_%s).\n" ,
74
+ shmemq_error ,
75
+ shmemq_error_str (shmemq_error )
76
+ );
73
77
break ;
74
78
}
75
79
}
Original file line number Diff line number Diff line change @@ -88,7 +88,13 @@ int main()
88
88
}
89
89
90
90
finalize :
91
- if (shmemq_error != SHMEMQ_ERROR_NONE ) printf ("Error: %u.\n" , shmemq_error );
91
+ if (shmemq_error != SHMEMQ_ERROR_NONE ) {
92
+ printf (
93
+ "Error: %u (SHMEMQ_ERROR_%s).\n" ,
94
+ shmemq_error ,
95
+ shmemq_error_str (shmemq_error )
96
+ );
97
+ }
92
98
93
99
printf ("Destroy queue.\n" );
94
100
Original file line number Diff line number Diff line change @@ -78,6 +78,8 @@ typedef struct Shmemq {
78
78
struct ShmemqBuffer * buffer ;
79
79
} * Shmemq ;
80
80
81
+ const char * shmemq_error_str (ShmemqError error );
82
+
81
83
Shmemq shmemq_new (const char * name , bool is_consumer , ShmemqError * error_ptr );
82
84
83
85
void shmemq_init (
Original file line number Diff line number Diff line change 9
9
#include <sys/stat.h>
10
10
#include <unistd.h>
11
11
12
+ const char * shmemq_error_str (const ShmemqError error )
13
+ {
14
+ switch (error ) {
15
+ case SHMEMQ_ERROR_NONE :
16
+ return "NONE" ;
17
+ case SHMEMQ_ERROR_INVALID_NAME :
18
+ return "INVALID_NAME" ;
19
+ case SHMEMQ_ERROR_BUG_POP_END_ON_EMPTY_QUEUE :
20
+ return "BUG_POP_END_ON_EMPTY_QUEUE" ;
21
+ case SHMEMQ_ERROR_BUG_PUSH_END_ON_FULL_QUEUE :
22
+ return "BUG_PUSH_END_ON_FULL_QUEUE" ;
23
+ case SHMEMQ_ERROR_BUG_PUSH_END_OVERFLOW :
24
+ return "BUG_PUSH_END_OVERFLOW" ;
25
+ case SHMEMQ_ERROR_FAILED_MALLOC :
26
+ return "FAILED_MALLOC" ;
27
+ case SHMEMQ_ERROR_FAILED_SHM_OPEN :
28
+ return "FAILED_SHM_OPEN" ;
29
+ case SHMEMQ_ERROR_FAILED_FTRUNCATE :
30
+ return "FAILED_FTRUNCATE" ;
31
+ case SHMEMQ_ERROR_FAILED_MMAP :
32
+ return "FAILED_MMAP" ;
33
+ case SHMEMQ_ERROR_FAILED_MUNMAP :
34
+ return "FAILED_MUNMAP" ;
35
+ case SHMEMQ_ERROR_FAILED_CLOSE :
36
+ return "FAILED_CLOSE" ;
37
+ case SHMEMQ_ERROR_FAILED_SHM_UNLINK :
38
+ return "FAILED_SHM_UNLINK" ;
39
+ case SHMEMQ_ERROR_FAILED_SEM_INIT :
40
+ return "FAILED_SEM_INIT" ;
41
+ default :
42
+ return "UNKNOWN" ;
43
+ }
44
+ }
45
+
12
46
void shmemq_delete (const Shmemq shmemq , ShmemqError * const error_ptr )
13
47
{
14
48
shmemq_finish (shmemq , error_ptr );
Original file line number Diff line number Diff line change
1
+ #include <shmemq.h>
2
+
3
+ #include <assert.h>
4
+ #include <string.h>
5
+
6
+ static void test (const ShmemqError shmemq_error , const char * const expected )
7
+ {
8
+ assert (strcmp (shmemq_error_str (shmemq_error ), expected ) == 0 );
9
+ }
10
+
11
+ int main ()
12
+ {
13
+ test (49 , "UNKNOWN" );
14
+ test (99 , "UNKNOWN" );
15
+ test (149 , "UNKNOWN" );
16
+
17
+ test (SHMEMQ_ERROR_NONE , "NONE" );
18
+ test (SHMEMQ_ERROR_INVALID_NAME , "INVALID_NAME" );
19
+ test (SHMEMQ_ERROR_BUG_POP_END_ON_EMPTY_QUEUE , "BUG_POP_END_ON_EMPTY_QUEUE" );
20
+ test (SHMEMQ_ERROR_BUG_PUSH_END_ON_FULL_QUEUE , "BUG_PUSH_END_ON_FULL_QUEUE" );
21
+ test (SHMEMQ_ERROR_BUG_PUSH_END_OVERFLOW , "BUG_PUSH_END_OVERFLOW" );
22
+ test (SHMEMQ_ERROR_FAILED_MALLOC , "FAILED_MALLOC" );
23
+ test (SHMEMQ_ERROR_FAILED_SHM_OPEN , "FAILED_SHM_OPEN" );
24
+ test (SHMEMQ_ERROR_FAILED_FTRUNCATE , "FAILED_FTRUNCATE" );
25
+ test (SHMEMQ_ERROR_FAILED_MMAP , "FAILED_MMAP" );
26
+ test (SHMEMQ_ERROR_FAILED_MUNMAP , "FAILED_MUNMAP" );
27
+ test (SHMEMQ_ERROR_FAILED_CLOSE , "FAILED_CLOSE" );
28
+ test (SHMEMQ_ERROR_FAILED_SHM_UNLINK , "FAILED_SHM_UNLINK" );
29
+ test (SHMEMQ_ERROR_FAILED_SEM_INIT , "FAILED_SEM_INIT" );
30
+
31
+ return 0 ;
32
+ }
You can’t perform that action at this time.
0 commit comments