Skip to contentSkip to conversation

unit: check cipher support and cleanup in test-storage

PATCH In review James Prestwood 2 participants 5 messages May 5, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 unit: check cipher support and cleanup in test-storage

The __storage_decrypt API requires AES_CTR so support should be checked before running that test. In addition storage_exit was never being called which leaves unbalanced mlock/munlock calls.

---
 unit/test-storage.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
unit/test-storage.c +9 -2
index c40518e6..765d9967 100644
@@ -44,12 +44,19 @@ static void test_short_encrypted_bytes(const void *data)
 
 int main(int argc, char *argv[])
 {
+	int ret;
+
 	l_test_init(&argc, &argv);
 
 	storage_init((const uint8_t *)"abc123", 6);
 
-	l_test_add("/storage/profile encryption",
+	if (l_cipher_is_supported(L_CIPHER_AES_CTR))
+		l_test_add("/storage/profile encryption",
 			test_short_encrypted_bytes, NULL);
 
-	return l_test_run();
+	ret = l_test_run();
+
+	storage_exit();
+
+	return ret;
 }
Signature · 1 line
2.34.1
#1 lore raw

Hi James,

Quoted 15 lines

The __storage_decrypt API requires AES_CTR so support should be checked before running that test. In addition storage_exit was never being called which leaves unbalanced mlock/munlock calls.
---
unit/test-storage.c | 11 +++++++++--

1 file changed, 9 insertions(+), 2 deletions(-)
unit/test-storage.c +0 -0
index c40518e6..765d9967 100644
@@ -44,12 +44,19 @@ static void test_short_encrypted_bytes(const void *data)
 
 int main(int argc, char *argv[])
 {

unit/test-storage.c static void test_short_encrypted_bytes(const void *data) · line 55

Quoted 10 lines
unit/test-storage.c +4 -1
+ int ret;
+
 l_test_init(&argc, &argv);
 
 storage_init((const uint8_t *)"abc123", 6);
 
- l_test_add("/storage/profile encryption",
+ if (l_cipher_is_supported(L_CIPHER_AES_CTR))
+ l_test_add("/storage/profile encryption",
 test_short_encrypted_bytes, NULL);

just use L_TEST_FLAG_ALLOW_FAILURE instead.

unit/test-storage.c static void test_short_encrypted_bytes(const void *data) · line 61

Quoted 6 lines
unit/test-storage.c +5 -1
- return l_test_run();
+ ret = l_test_run();
+
+ storage_exit();
+
+ return ret;

I really prefer we keep “return l_test_run()” as the basics on how test case are run.

Just put storage_init,storage_exit into the test case itself. I would just do system_key_set = false in the exit function.

Regards

Marcel

#2 lore raw

Hi,

Quoted 21 lines · Marcel Holtmann

Hi James,

Quoted 19 lines

The __storage_decrypt API requires AES_CTR so support should be checked before running that test. In addition storage_exit was never being called which leaves unbalanced mlock/munlock calls.
---
unit/test-storage.c | 11 +++++++++--

1 file changed, 9 insertions(+), 2 deletions(-)
unit/test-storage.c +2 -0
index c40518e6..765d9967 100644
@@ -44,12 +44,19 @@ static void test_short_encrypted_bytes(const void *data)
 
 int main(int argc, char *argv[])
 {
+ int ret;
+
 l_test_init(&argc, &argv);
 
Quoted 7 lines

unit/test-storage.c static void test_short_encrypted_bytes(const void *data) · line 55

Quoted 6 lines
unit/test-storage.c +2 -1
 storage_init((const uint8_t *)"abc123", 6);
 
- l_test_add("/storage/profile encryption",
+ if (l_cipher_is_supported(L_CIPHER_AES_CTR))
+ l_test_add("/storage/profile encryption",
 test_short_encrypted_bytes, NULL);

just use L_TEST_FLAG_ALLOW_FAILURE instead.

Ok, new way of doing things I guess.

Quoted 10 lines

unit/test-storage.c static void test_short_encrypted_bytes(const void *data) · line 61

Quoted 7 lines
unit/test-storage.c +5 -1
- return l_test_run();
+ ret = l_test_run();
+
+ storage_exit();
+
+ return ret;

I really prefer we keep “return l_test_run()” as the basics on how test case are run.

Just put storage_init,storage_exit into the test case itself. I would just do system_key_set = false in the exit function.

I'm fine with this, but its actually not possible to perform the cleanup after a failed test. If we want to do this we need actual cleanup support in l_test. Looks like we'd need to add a destroy function to l_test_add_data_func().

Does that sound ok?

Thanks,

James

Quoted 5 lines

Regards

Marcel

#3 lore raw

Hi James,

Quoted 36 lines
Quoted 19 lines
Quoted 19 lines

The __storage_decrypt API requires AES_CTR so support should be checked before running that test. In addition storage_exit was never being called which leaves unbalanced mlock/munlock calls.
---
unit/test-storage.c | 11 +++++++++--

1 file changed, 9 insertions(+), 2 deletions(-)
unit/test-storage.c +2 -0
index c40518e6..765d9967 100644
@@ -44,12 +44,19 @@ static void test_short_encrypted_bytes(const void *data)
 
 int main(int argc, char *argv[])
 {
+ int ret;
+
 l_test_init(&argc, &argv);
 
Quoted 7 lines

unit/test-storage.c static void test_short_encrypted_bytes(const void *data) · line 55

Quoted 6 lines
unit/test-storage.c +2 -1
 storage_init((const uint8_t *)"abc123", 6);
 
- l_test_add("/storage/profile encryption",
+ if (l_cipher_is_supported(L_CIPHER_AES_CTR))
+ l_test_add("/storage/profile encryption",
 test_short_encrypted_bytes, NULL);

just use L_TEST_FLAG_ALLOW_FAILURE instead.

Ok, new way of doing things I guess.

Quoted 9 lines

unit/test-storage.c static void test_short_encrypted_bytes(const void *data) · line 61

Quoted 7 lines
unit/test-storage.c +5 -1
- return l_test_run();
+ ret = l_test_run();
+
+ storage_exit();
+
+ return ret;

I really prefer we keep “return l_test_run()” as the basics on how test case are run.

Quoted 5 lines
Quoted 1 line

Just put storage_init,storage_exit into the test case itself. I would just do system_key_set = false in the exit function.

I'm fine with this, but its actually not possible to perform the cleanup after a failed test. If we want to do this we need actual cleanup support in l_test. Looks like we'd need to add a destroy function to l_test_add_data_func().

Does that sound ok?

we can add that, but I don’t think it is needed. Every test case is run in its own process. And since you only have one test case at the moment, don’t over engineer this.

Regards

Marcel

#4 lore raw

Hi,

Quoted 37 lines · Marcel Holtmann

Hi James,

Quoted 35 lines
Quoted 19 lines
Quoted 19 lines

The __storage_decrypt API requires AES_CTR so support should be checked before running that test. In addition storage_exit was never being called which leaves unbalanced mlock/munlock calls.
---
unit/test-storage.c | 11 +++++++++--

1 file changed, 9 insertions(+), 2 deletions(-)
unit/test-storage.c +2 -0
index c40518e6..765d9967 100644
@@ -44,12 +44,19 @@ static void test_short_encrypted_bytes(const void *data)
 
 int main(int argc, char *argv[])
 {
+ int ret;
+
 l_test_init(&argc, &argv);
 
Quoted 7 lines

unit/test-storage.c static void test_short_encrypted_bytes(const void *data) · line 55

Quoted 6 lines
unit/test-storage.c +2 -1
 storage_init((const uint8_t *)"abc123", 6);
 
- l_test_add("/storage/profile encryption",
+ if (l_cipher_is_supported(L_CIPHER_AES_CTR))
+ l_test_add("/storage/profile encryption",
 test_short_encrypted_bytes, NULL);

just use L_TEST_FLAG_ALLOW_FAILURE instead.

Ok, new way of doing things I guess.

Quoted 8 lines

unit/test-storage.c static void test_short_encrypted_bytes(const void *data) · line 61

Quoted 6 lines
unit/test-storage.c +5 -1
- return l_test_run();
+ ret = l_test_run();
+
+ storage_exit();
+
+ return ret;

I really prefer we keep “return l_test_run()” as the basics on how test case are run.

Quoted 5 lines
Quoted 4 lines
Quoted 1 line

Just put storage_init,storage_exit into the test case itself. I would just do system_key_set = false in the exit function.

I'm fine with this, but its actually not possible to perform the cleanup after a failed test. If we want to do this we need actual cleanup support in l_test. Looks like we'd need to add a destroy function to l_test_add_data_func().

Does that sound ok?

we can add that, but I don’t think it is needed. Every test case is run in its own process. And since you only have one test case at the moment, don’t over engineer this.

Yeah, but what I'm saying is that there is no way to perform cleanup if a test asserts. In this case though I actually don't think storage_exit() is technically needed since the OS process cleanup will munlock any pages. So for now I'll just add the flag and leave everything else as-is.

Quoted 5 lines

Regards

Marcel