-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_nextvar.c
122 lines (101 loc) · 3.21 KB
/
test_nextvar.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* Copyright 2019 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "test.c"
char *test_name = "nextvar";
int run_test(void)
{
int64_t rc;
struct secvar *tmpvar;
wchar_t name[1024] = {0};
char vendor[1024] = {0}; // TODO: use actual vendor here
uint32_t attributes = 0;
uint64_t size = 16;
// Load up the bank with some variables.
// If these fail, we have bigger issues.
ASSERT(list_length(&variable_bank) == 0);
tmpvar = zalloc(sizeof(struct secvar));
memcpy(tmpvar->name, L"test1", 5*2);
tmpvar->attributes = 27;
tmpvar->data_size = 16;
tmpvar->data = zalloc(16); // unused
list_add_tail(&variable_bank, &tmpvar->link);
ASSERT(list_length(&variable_bank) == 1);
tmpvar = zalloc(sizeof(struct secvar));
memcpy(tmpvar->name, L"test2", 5*2);
tmpvar->attributes = 32;
tmpvar->data_size = 10;
tmpvar->data = zalloc(10); // unused
list_add_tail(&variable_bank, &tmpvar->link);
ASSERT(list_length(&variable_bank) == 2);
tmpvar = zalloc(sizeof(struct secvar));
memcpy(tmpvar->name, L"test3", 5*2);
tmpvar->attributes = 16;
tmpvar->data_size = 32;
tmpvar->data = zalloc(32); // unused
list_add_tail(&variable_bank, &tmpvar->link);
ASSERT(list_length(&variable_bank) == 3);
// Test sequential nexts
// first item
size = sizeof(name);
memset(name, 0, sizeof(name));
rc = secvar_get_next(&size, name, vendor);
ASSERT(rc == OPAL_SUCCESS);
ASSERT(!memcmp(name, L"test1", 5*2));
// second item
rc = secvar_get_next(&size, name, vendor);
ASSERT(rc == OPAL_SUCCESS);
ASSERT(!memcmp(name, L"test2", 5*2));
// last item
rc = secvar_get_next(&size, name, vendor);
ASSERT(rc == OPAL_SUCCESS);
ASSERT(!memcmp(name, L"test3", 5*2));
// end-of-list
rc = secvar_get_next(&size, name, vendor);
ASSERT(rc == OPAL_EMPTY);
memset(name, 0, sizeof(name));
/*** Time for a break to test bad parameters ***/
// null name
rc = secvar_get_next(&size, NULL, vendor);
ASSERT(rc == OPAL_PARAMETER);
// null vendor
rc = secvar_get_next(&size, name, NULL);
ASSERT(rc == OPAL_PARAMETER);
// Size too small
size = 1;
rc = secvar_get_next(&size, name, vendor);
ASSERT(rc == OPAL_PARTIAL);
ASSERT(size == 10);
// NULL size pointer
rc = secvar_get_next(NULL, name, vendor);
ASSERT(rc == OPAL_PARAMETER);
// zero size
size = 0;
rc = secvar_get_next(&size, name, vendor);
ASSERT(rc == OPAL_PARAMETER);
// Non-existing previous variable
size = 1024;
memcpy(name, L"foobar", 7*2);
rc = secvar_get_next(&size, name, vendor);
ASSERT(rc == OPAL_PARAMETER);
memset(name, 1, sizeof(name));
rc = secvar_get_next(&size, name, vendor);
ASSERT(rc == OPAL_PARAMETER);
secvar_enabled = 0;
rc = secvar_get_next(&size, name, vendor);
ASSERT(rc == OPAL_HARDWARE);
clear_bank_list(&variable_bank);
return 0;
}