Skip to content

Commit 9d4fcae

Browse files
committed
Release v3.7.1 (20231215) update
1 parent c6c6adc commit 9d4fcae

3 files changed

Lines changed: 394 additions & 0 deletions

File tree

test/hal/test_hal.c

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/**
2+
* \file
3+
* \brief Tests for the cryptoauthlib talib API
4+
*
5+
* \copyright (c) 2015-2023 Microchip Technology Inc. and its subsidiaries.
6+
*
7+
* \page License
8+
*
9+
* Subject to your compliance with these terms, you may use Microchip software
10+
* and any derivatives exclusively with Microchip products. It is your
11+
* responsibility to comply with third party license terms applicable to your
12+
* use of third party software (including open source software) that may
13+
* accompany Microchip software.
14+
*
15+
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
16+
* EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
17+
* WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
18+
* PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT,
19+
* SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE
20+
* OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
21+
* MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
22+
* FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL
23+
* LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED
24+
* THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR
25+
* THIS SOFTWARE.
26+
*/
27+
28+
#include "atca_test.h"
29+
#include "test_hal.h"
30+
31+
extern t_test_case_info hal_basic_tests[];
32+
33+
/* Tests are ordered based on successive capability used by commands. If a command
34+
* is used in a test then it is tested ahead of the other. E.g. verify is tested
35+
* using verify
36+
*/
37+
static t_test_case_info* hal_test_list[] =
38+
{
39+
hal_basic_tests,
40+
/* Array Termination element*/
41+
(t_test_case_info*)NULL,
42+
};
43+
44+
void run_hal_tests(void)
45+
{
46+
RunAllTests(hal_test_list);
47+
}
48+
49+
int hal_tests(int argc, char* argv[])
50+
{
51+
return run_test(argc, argv, run_hal_tests);
52+
}
53+
54+
const char* HAL_HELPER_FILE = "In helper: " __FILE__;
55+
const char* TEST_GROUP_hal = "hal";
56+
57+
TEST_SETUP(hal)
58+
{
59+
#ifdef ATCA_PRINTF
60+
printf("\n");
61+
fflush(stdout);
62+
fflush(stderr);
63+
#endif
64+
65+
UnityMalloc_StartTest();
66+
67+
ATCA_STATUS status = atcab_init(gCfg);
68+
TEST_ASSERT_SUCCESS_MSG(status, HAL_HELPER_FILE);
69+
}
70+
71+
TEST_TEAR_DOWN(hal)
72+
{
73+
ATCA_STATUS status;
74+
bool test_failed = atca_test_already_exiting();
75+
bool comm_failed = atca_test_unresponsive();
76+
77+
if (comm_failed)
78+
{
79+
/* Assume if there are comm failures there isn't a point trying to
80+
continue to fail here */
81+
status = atcab_wakeup();
82+
if (!test_failed)
83+
{
84+
TEST_ASSERT_SUCCESS_MSG(status, HAL_HELPER_FILE);
85+
}
86+
87+
status = atcab_sleep();
88+
if (!test_failed)
89+
{
90+
TEST_ASSERT_SUCCESS_MSG(status, HAL_HELPER_FILE);
91+
}
92+
}
93+
94+
status = atcab_release();
95+
if (!test_failed && !comm_failed)
96+
{
97+
/* Don't override the existing failure location or the global
98+
status return value */
99+
TEST_ASSERT_SUCCESS_MSG(status, HAL_HELPER_FILE);
100+
}
101+
102+
UnityMalloc_EndTest();
103+
}

test/hal/test_hal.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* \file
3+
* \brief Tests to cover hal layer functionality
4+
*
5+
* \copyright (c) 2015-2023 Microchip Technology Inc. and its subsidiaries.
6+
*
7+
* \page License
8+
*
9+
* Subject to your compliance with these terms, you may use Microchip software
10+
* and any derivatives exclusively with Microchip products. It is your
11+
* responsibility to comply with third party license terms applicable to your
12+
* use of third party software (including open source software) that may
13+
* accompany Microchip software.
14+
*
15+
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
16+
* EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
17+
* WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
18+
* PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT,
19+
* SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE
20+
* OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
21+
* MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
22+
* FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL
23+
* LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED
24+
* THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR
25+
* THIS SOFTWARE.
26+
*/
27+
28+
#ifndef TEST_HAL_H_
29+
#define TEST_HAL_H_
30+
31+
#include "atca_test.h"
32+
33+
#ifdef __cplusplus
34+
extern "C" {
35+
#endif
36+
37+
38+
/* Test Commands */
39+
int hal_tests(int argc, char* argv[]);
40+
41+
/* Common test setup/teardown */
42+
extern const char* TEST_GROUP_hal;
43+
void TEST_hal_SETUP(void);
44+
void TEST_hal_TEAR_DOWN(void);
45+
46+
#ifdef __cplusplus
47+
}
48+
#endif
49+
50+
#endif /* TEST_HAL_H_*/

test/hal/test_hal_basic.c

Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
/**
2+
* \file
3+
* \brief Hal functionality Tests for ECC and TrustAnchor Devices
4+
*
5+
* \copyright (c) 2015-2023 Microchip Technology Inc. and its subsidiaries.
6+
*
7+
* \page License
8+
*
9+
* Subject to your compliance with these terms, you may use Microchip software
10+
* and any derivatives exclusively with Microchip products. It is your
11+
* responsibility to comply with third party license terms applicable to your
12+
* use of third party software (including open source software) that may
13+
* accompany Microchip software.
14+
*
15+
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
16+
* EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
17+
* WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
18+
* PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT,
19+
* SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE
20+
* OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
21+
* MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
22+
* FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL
23+
* LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED
24+
* THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR
25+
* THIS SOFTWARE.
26+
*/
27+
28+
#include "atca_test.h"
29+
#include "test_hal.h"
30+
31+
#ifndef TEST_HAL_RANDOM_EN
32+
#define TEST_HAL_RANDOM_EN CALIB_RANDOM_EN || TALIB_RANDOM_EN
33+
#endif
34+
35+
TEST_SETUP(hal_basic_tests)
36+
{
37+
/* Common Setup */
38+
TEST_hal_SETUP();
39+
}
40+
41+
TEST_TEAR_DOWN(hal_basic_tests)
42+
{
43+
/* Common Cleanup */
44+
TEST_hal_TEAR_DOWN();
45+
}
46+
47+
TEST_CONDITION(hal, hal_test_condn)
48+
{
49+
ATCADeviceType dev_type = atca_test_get_device_type();
50+
51+
return (atcab_is_ca_device(dev_type)
52+
|| atcab_is_ca2_device(dev_type)
53+
|| atcab_is_ta_device(dev_type));
54+
}
55+
56+
/** \brief This test case gets revision number from the device
57+
*/
58+
TEST(hal, read_info)
59+
{
60+
ATCA_STATUS status = ATCA_GEN_FAIL;
61+
uint8_t revision[4];
62+
63+
status = atcab_info(revision);
64+
TEST_ASSERT_SUCCESS(status);
65+
}
66+
67+
/** \brief This test case gets serial number from the device
68+
*/
69+
TEST(hal, read_serial_number)
70+
{
71+
ATCA_STATUS status;
72+
uint8_t serialnum[9];
73+
74+
status = atcab_read_serial_number(serialnum);
75+
TEST_ASSERT_SUCCESS(status);
76+
}
77+
78+
#if TEST_HAL_RANDOM_EN
79+
TEST_CONDITION(hal, random)
80+
{
81+
ATCADeviceType dev_type = atca_test_get_device_type();
82+
83+
return (atcab_is_ca_device(dev_type) && (ATSHA206A != dev_type))
84+
|| atcab_is_ta_device(dev_type)
85+
;
86+
}
87+
88+
/** \brief This test case generates random number from the device
89+
*/
90+
TEST(hal, random)
91+
{
92+
ATCA_STATUS status = ATCA_GEN_FAIL;
93+
uint8_t randomnum[32];
94+
95+
status = atcab_random(randomnum);
96+
TEST_ASSERT_EQUAL(ATCA_SUCCESS, status);
97+
}
98+
#endif
99+
100+
#if ATCA_TA_SUPPORT
101+
TEST_CONDITION(hal, ta_single_and_multi_part_write_read)
102+
{
103+
ATCADeviceType dev_type = atca_test_get_device_type();
104+
105+
return (atcab_is_ta_device(dev_type));
106+
}
107+
108+
/** \brief This test case creates a handle and checks whether data written is same when read for TA devices
109+
* Supports both single part and multipart buffers
110+
*/
111+
TEST(hal, ta_single_and_multi_part_write_read)
112+
{
113+
ATCA_STATUS status;
114+
ta_element_attributes_t attr_data_handle;
115+
uint16_t data_handle;
116+
uint16_t test_element_size[] = { 200, 1021, 1024, 2048 };
117+
uint8_t write_data_buffer[2048]; //! taking max buffer size for test
118+
uint8_t read_data_buffer[2048]; //! taking max buffer size for test
119+
uint16_t write_element_size, read_element_size;
120+
uint8_t index;
121+
uint8_t stir_data[16] = { 0 };
122+
cal_buffer stir_data_buf = CAL_BUF_INIT(sizeof(stir_data), stir_data);
123+
cal_buffer write_data_buf = { 0 };
124+
cal_buffer read_data_buf = { 0 };
125+
126+
// Skip test if setup isn't locked
127+
test_assert_data_is_locked();
128+
129+
130+
for (index = 0; index < sizeof(test_element_size) / sizeof(test_element_size[0]); index++)
131+
{
132+
write_element_size = test_element_size[index];
133+
read_element_size = test_element_size[index];
134+
135+
write_data_buf.len = write_element_size;
136+
write_data_buf.buf = write_data_buffer;
137+
138+
read_data_buf.len = read_element_size;
139+
read_data_buf.buf = read_data_buffer;
140+
141+
status = talib_handle_init_data(&attr_data_handle, write_element_size);
142+
TEST_ASSERT_EQUAL(ATCA_SUCCESS, status);
143+
144+
status = talib_create_element(atcab_get_device(), &attr_data_handle, &data_handle);
145+
TEST_ASSERT_EQUAL(ATCA_SUCCESS, status);
146+
147+
//Reset data buffers... Read buffer with 0's and Write buffer with random data
148+
memset(read_data_buf.buf, 0x0, read_data_buf.len);
149+
150+
status = talib_random(atcab_get_device(), &stir_data_buf, &write_data_buf);
151+
TEST_ASSERT_EQUAL(ATCA_SUCCESS, status);
152+
153+
status = talib_write_element(atcab_get_device(), data_handle, &write_data_buf);
154+
TEST_ASSERT_EQUAL(ATCA_SUCCESS, status);
155+
156+
status = talib_read_element(atcab_get_device(), data_handle, &read_data_buf);
157+
TEST_ASSERT_EQUAL(ATCA_SUCCESS, status);
158+
TEST_ASSERT_EQUAL_MEMORY(write_data_buf.buf, read_data_buf.buf, write_element_size);
159+
160+
status = talib_delete_handle(atcab_get_device(), (uint32_t)data_handle);
161+
TEST_ASSERT_EQUAL(ATCA_SUCCESS, status);
162+
}
163+
}
164+
#endif
165+
166+
/** \brief This test case checks whether data written is same when read for CA or TA devices
167+
*/
168+
TEST(hal, single_part_write_read)
169+
{
170+
ATCA_STATUS status = ATCA_SUCCESS;
171+
uint8_t write_data[64];
172+
uint8_t read_data[sizeof(write_data)];
173+
uint16_t slot;
174+
175+
/* Note - This test assumes ECC slot sizes */
176+
if (atcab_is_ca2_device(gCfg->devtype))
177+
{
178+
/* This test for the ECC204 needs to be run when the device data is unlocked
179+
Config Subzone 0 and 1 should be locked */
180+
test_assert_config_is_locked();
181+
test_assert_data_is_unlocked();
182+
}
183+
else
184+
{
185+
/* For all other devices it has to be run when data zone is locked */
186+
test_assert_data_is_locked();
187+
}
188+
189+
status = atca_test_config_get_id(TEST_TYPE_DATA, &slot);
190+
TEST_ASSERT_EQUAL(ATCA_SUCCESS, status);
191+
192+
if (!atcab_is_ca2_device(gCfg->devtype))
193+
{
194+
#if CALIB_RANDOM_EN
195+
// Generate random data to be written
196+
status = atcab_random(&write_data[0]);
197+
TEST_ASSERT_EQUAL(ATCA_SUCCESS, status);
198+
status = atcab_random(&write_data[ATCA_BLOCK_SIZE]);
199+
TEST_ASSERT_EQUAL(ATCA_SUCCESS, status);
200+
#endif
201+
}
202+
else
203+
{
204+
memset(write_data, 0x5A, sizeof(write_data));
205+
}
206+
207+
// Test cross-block writes
208+
status = atcab_write_bytes_zone(ATCA_ZONE_DATA, slot, 4, write_data, sizeof(write_data));
209+
TEST_ASSERT_EQUAL(ATCA_SUCCESS, status);
210+
211+
if (!atcab_is_ca2_device(gCfg->devtype))
212+
{
213+
status = atcab_read_bytes_zone(ATCA_ZONE_DATA, slot, 4, read_data, sizeof(read_data));
214+
TEST_ASSERT_EQUAL(ATCA_SUCCESS, status);
215+
}
216+
else
217+
{
218+
status = atcab_read_bytes_zone(ATCA_ZONE_DATA, slot, 128, read_data, sizeof(read_data));
219+
TEST_ASSERT_EQUAL(ATCA_SUCCESS, status);
220+
}
221+
222+
TEST_ASSERT_EQUAL_MEMORY(write_data, read_data, sizeof(write_data));
223+
}
224+
225+
// *INDENT-OFF* - Preserve formatting
226+
t_test_case_info hal_basic_tests[] =
227+
{
228+
{ REGISTER_TEST_CASE(hal, read_info), REGISTER_TEST_CONDITION(hal, hal_test_condn) },
229+
{ REGISTER_TEST_CASE(hal, read_serial_number), REGISTER_TEST_CONDITION(hal, hal_test_condn) },
230+
#if TEST_HAL_RANDOM_EN
231+
{ REGISTER_TEST_CASE(hal, random), REGISTER_TEST_CONDITION(hal, random) },
232+
#endif
233+
#if ATCA_TA_SUPPORT
234+
{ REGISTER_TEST_CASE(hal, ta_single_and_multi_part_write_read), REGISTER_TEST_CONDITION(hal, ta_single_and_multi_part_write_read) },
235+
#endif
236+
{ REGISTER_TEST_CASE(hal, single_part_write_read), REGISTER_TEST_CONDITION(hal, hal_test_condn) },
237+
/* Array Termination element*/
238+
{ (fp_test_case)NULL, NULL },
239+
};
240+
// *INDENT-OFF*
241+

0 commit comments

Comments
 (0)