1 #include "tls_test_frame.h"
2 
3 /* Construct a tls test instance. */
tls_test_instance_create(TLS_TEST_INSTANCE ** instance_ptr_ptr,CHAR * instance_name,InstanceTestEntryFunc test_entry,UINT delay,UINT timeout,UINT shared_buffer_size,VOID * reserved)4 INT tls_test_instance_create( TLS_TEST_INSTANCE** instance_ptr_ptr, CHAR* instance_name, InstanceTestEntryFunc test_entry, UINT delay, UINT timeout, UINT shared_buffer_size, VOID* reserved)
5 {
6     /* Check parameters. */
7     return_value_if_fail( NULL != instance_ptr_ptr, TLS_TEST_INVALID_POINTER);
8     return_value_if_fail( NULL != instance_name, TLS_TEST_INVALID_POINTER);
9     return_value_if_fail( NULL != test_entry, TLS_TEST_INVALID_POINTER);
10 
11     /* Allocate shared memory of this test instance and its shared buffer. */
12     TLS_TEST_INSTANCE* instance_ptr;
13     instance_ptr = mmap( NULL, sizeof(TLS_TEST_INSTANCE) + shared_buffer_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, 0, 0);
14     return_value_if_fail( NULL != instance_ptr, TLS_TEST_UNABLE_TO_CREATE_SHARED_MEMORY);
15 
16     /* Return instance ptr. */
17     *instance_ptr_ptr = instance_ptr;
18 
19     /* Initialize members related to shared buffer. */
20     instance_ptr -> tls_test_shared_buffer_size = shared_buffer_size;
21     instance_ptr -> tls_test_shared_buffer_offset = 0;
22     if ( shared_buffer_size)
23     {
24         instance_ptr -> tls_test_shared_buffer = (VOID*)( (CHAR*)instance_ptr + sizeof(TLS_TEST_INSTANCE));
25     }
26     else
27     {
28         instance_ptr -> tls_test_shared_buffer = NULL;
29     }
30 
31     /* Initialize other members. */
32     instance_ptr -> tls_test_instance_name = instance_name;
33     instance_ptr -> tls_test_entry = test_entry;
34     instance_ptr -> tls_test_delay = delay;
35     if ( !timeout)
36     {
37         /* Assign timeout as default value, if timeout is 0. */
38         instance_ptr -> tls_test_timeout = TLS_TEST_PROCESS_DEFAULT_TIMEOUT;
39     }
40     else
41     {
42         instance_ptr -> tls_test_timeout = timeout;
43     }
44 
45     instance_ptr -> tls_test_instance_identify = 0;
46     instance_ptr -> tls_test_instance_status = TLS_TEST_INSTANCE_STATUS_INITIALIZED;
47     instance_ptr -> tls_test_next_instance_ptr = NULL;
48 
49     return TLS_TEST_SUCCESS;
50 }
51