aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/GNUmakefile18
-rw-r--r--tests/test-rpc_get_version.c20
-rw-r--r--tests/test-rpc_hash.c30
-rw-r--r--tests/test-rpc_server.c12
4 files changed, 62 insertions, 18 deletions
diff --git a/tests/GNUmakefile b/tests/GNUmakefile
index 4bb5f72..63db700 100644
--- a/tests/GNUmakefile
+++ b/tests/GNUmakefile
@@ -29,8 +29,22 @@
INC = ../hal.h
LIB = ../libhal.a
-BIN = test-aes-key-wrap test-hash test-pbkdf2 test-ecdsa test-bus test-trng test-rsa
-BIN += test-rpc_hash test-rpc_server test-rpc_pkey
+BIN := test-aes-key-wrap test-hash test-pbkdf2 test-ecdsa test-bus test-trng test-rsa
+ifndef RPC_SERVER
+ ifdef RPC_CLIENT
+ ifneq (${RPC_CLIENT},local)
+ # If we're only building a remote RPC client lib, don't include
+ # tests that access the FPGA cores.
+ BIN :=
+ endif
+ endif
+endif
+ifdef RPC_CLIENT
+ BIN += test-rpc_hash test-rpc_pkey test-rpc_get_version
+endif
+ifdef RPC_SERVER
+ BIN += test-rpc_server
+endif
CFLAGS = -g3 -Wall -fPIC -std=c99 -I..
diff --git a/tests/test-rpc_get_version.c b/tests/test-rpc_get_version.c
new file mode 100644
index 0000000..84869c3
--- /dev/null
+++ b/tests/test-rpc_get_version.c
@@ -0,0 +1,20 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <assert.h>
+
+#include <hal.h>
+#include <hal_internal.h>
+
+int main (int argc, char *argv[])
+{
+ uint32_t version;
+
+#define check(op) { hal_error_t err; if ((err = (op)) != HAL_OK) { printf("%s: %s\n", #op, hal_error_string(err)); return 1; } }
+
+ check(hal_rpc_client_init());
+ check(hal_rpc_get_version(&version));
+ printf("%08x\n", version);
+
+ return 0;
+}
diff --git a/tests/test-rpc_hash.c b/tests/test-rpc_hash.c
index ded440f..22bc589 100644
--- a/tests/test-rpc_hash.c
+++ b/tests/test-rpc_hash.c
@@ -538,6 +538,11 @@ static int _test_hash(const hal_digest_algorithm_t alg,
{
uint8_t digest[512];
hal_error_t err;
+ static hal_digest_algorithm_t last_alg = -1;
+ static hal_error_t last_err = -1;
+
+ if (last_alg == alg && last_err == HAL_ERROR_CORE_NOT_FOUND)
+ return 1;
assert(data != NULL && result != NULL && label != NULL);
assert(result_len <= sizeof(digest));
@@ -548,7 +553,10 @@ static int _test_hash(const hal_digest_algorithm_t alg,
hal_session_handle_t session = {0};
hal_hash_handle_t hash;
- if ((err = hal_rpc_hash_initialize(client, session, &hash, alg, NULL, 0)) != HAL_OK) {
+ err = hal_rpc_hash_initialize(client, session, &hash, alg, NULL, 0);
+ last_alg = alg;
+ last_err = err;
+ if (err != HAL_OK) {
printf("Failed while initializing hash: %s\n", hal_error_string(err));
return 0;
}
@@ -577,7 +585,8 @@ static int _test_hash(const hal_digest_algorithm_t alg,
}
printf("OK\n");
- return 1;
+ last_err = err;
+ return 1;
}
static int _test_hmac(const hal_digest_algorithm_t alg,
@@ -588,6 +597,11 @@ static int _test_hmac(const hal_digest_algorithm_t alg,
{
uint8_t digest[512];
hal_error_t err;
+ static hal_digest_algorithm_t last_alg = -1;
+ static hal_error_t last_err = -1;
+
+ if (last_alg == alg && last_err == HAL_ERROR_CORE_NOT_FOUND)
+ return 1;
assert(data != NULL && result != NULL && label != NULL);
assert(result_len <= sizeof(digest));
@@ -598,7 +612,10 @@ static int _test_hmac(const hal_digest_algorithm_t alg,
hal_session_handle_t session = {0};
hal_hash_handle_t hash;
- if ((err = hal_rpc_hash_initialize(client, session, &hash, alg, key, key_len)) != HAL_OK) {
+ err = hal_rpc_hash_initialize(client, session, &hash, alg, key, key_len);
+ last_alg = alg;
+ last_err = err;
+ if (err != HAL_OK) {
printf("Failed while initializing HMAC: %s\n", hal_error_string(err));
return 0;
}
@@ -638,11 +655,10 @@ static int _test_hmac(const hal_digest_algorithm_t alg,
int main (int argc, char *argv[])
{
-// rpc_client_init(RPC_LOCAL);
- rpc_client_init(RPC_REMOTE);
-
int ok = 1;
+ ok &= hal_rpc_client_init();
+
ok &= test_hash(hal_digest_algorithm_sha1, nist_512_single, sha1_single_digest, "SHA-1 single block");
ok &= test_hash(hal_digest_algorithm_sha1, nist_512_double, sha1_double_digest, "SHA-1 double block");
@@ -690,6 +706,8 @@ int main (int argc, char *argv[])
ok &= test_hmac(hal_digest_algorithm_sha512, hmac_sha2_tc_6_key, hmac_sha2_tc_6_data, hmac_sha2_tc_6_result_sha512, "HMAC-SHA-512 test case 6");
ok &= test_hmac(hal_digest_algorithm_sha512, hmac_sha2_tc_7_key, hmac_sha2_tc_7_data, hmac_sha2_tc_7_result_sha512, "HMAC-SHA-512 test case 7");
+ ok &= hal_rpc_client_close();
+
return !ok;
}
diff --git a/tests/test-rpc_server.c b/tests/test-rpc_server.c
index 6359cb5..eb11f6d 100644
--- a/tests/test-rpc_server.c
+++ b/tests/test-rpc_server.c
@@ -1,18 +1,10 @@
-#include <stdio.h>
-#include <stdint.h>
-#include <string.h>
-#include <assert.h>
-
#include <hal.h>
-#warning This is wrong, nothing outside libhal itself should include hal_internal.h
-#include <hal_internal.h>
-
int main (int argc, char *argv[])
{
- if (rpc_server_init() != HAL_OK)
+ if (hal_rpc_server_init() != HAL_OK)
return 1;
- rpc_server_main();
+ hal_rpc_server_main();
return 0;
}