summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/build.mk2
-rw-r--r--test/version.c149
-rw-r--r--test/version.tasklist9
3 files changed, 160 insertions, 0 deletions
diff --git a/test/build.mk b/test/build.mk
index ec9e66ead3..6785024d2e 100644
--- a/test/build.mk
+++ b/test/build.mk
@@ -105,6 +105,7 @@ test-list-host += usb_pe_drp_noextended
test-list-host += utils
test-list-host += utils_str
test-list-host += vboot
+test-list-host += version
test-list-host += x25519
test-list-host += stillness_detector
endif
@@ -242,6 +243,7 @@ usb_tcpmv2_compliance-y=usb_tcpmv2_compliance.o usb_tcpmv2_compliance_common.o \
utils-y=utils.o
utils_str-y=utils_str.o
vboot-y=vboot.o
+version-y += version.o
float-y=fp.o
fp-y=fp.o
x25519-y=x25519.o
diff --git a/test/version.c b/test/version.c
new file mode 100644
index 0000000000..ad7571d5f6
--- /dev/null
+++ b/test/version.c
@@ -0,0 +1,149 @@
+/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Test ec version
+ */
+
+#include "common.h"
+#include "ec_commands.h"
+#include "stddef.h"
+#include "system.h"
+#include "util.h"
+#include "test_util.h"
+
+/*
+ * Tests that fw version adheres to the expected format.
+ * Example fw version: host_v2.0.10135+b3e38e380c
+ */
+static int test_version(void)
+{
+ const char *fw_version;
+ size_t board_name_length, major_version_length, minor_version_length,
+ sub_minor_version_length, hash_length;
+ const char *major_version_ptr, *minor_version_ptr,
+ *sub_minor_version_ptr, *hash_ptr;
+
+ fw_version = system_get_version(EC_IMAGE_RO);
+
+ TEST_ASSERT(fw_version != NULL);
+
+ ccprintf("fw_version: %s\n", fw_version);
+
+ TEST_LE(strlen(fw_version), (size_t)32, "%zu");
+
+ board_name_length = strcspn(fw_version, "_");
+
+ TEST_GE(board_name_length, (size_t)3, "%zu");
+
+ major_version_ptr = fw_version + board_name_length + 1;
+ major_version_length = strcspn(major_version_ptr, ".");
+
+ TEST_GE(major_version_length, (size_t)2, "%zu");
+ TEST_EQ(major_version_ptr[0], 'v', "%c");
+ for (int i = 1; i < major_version_length; i++)
+ TEST_ASSERT(isdigit(major_version_ptr[i]));
+
+ minor_version_ptr = major_version_ptr + major_version_length + 1;
+ minor_version_length = strcspn(minor_version_ptr, ".");
+
+ TEST_GE(minor_version_length, (size_t)1, "%zu");
+ for (int i = 0; i < minor_version_length; i++)
+ TEST_ASSERT(isdigit(minor_version_ptr[i]));
+
+ sub_minor_version_ptr = minor_version_ptr + minor_version_length + 1;
+ sub_minor_version_length = strcspn(sub_minor_version_ptr, "-+");
+
+ TEST_GE(sub_minor_version_length, (size_t)1, "%zu");
+ for (int i = 0; i < sub_minor_version_length; i++)
+ TEST_ASSERT(isdigit(sub_minor_version_ptr[i]));
+
+ hash_ptr = sub_minor_version_ptr + sub_minor_version_length + 1;
+ hash_length = strlen(hash_ptr);
+
+ TEST_GE(hash_length, (size_t)8, "%zu");
+ for (int i = 0; i < hash_length; i++)
+ TEST_ASSERT(isdigit(hash_ptr[i]) ||
+ (hash_ptr[i] >= 'a' && hash_ptr[i] <= 'f'));
+
+ return EC_SUCCESS;
+}
+
+/*
+ * Tests that cros fwid adheres to the expected format.
+ * Example cros fwid: host_14175.0.21_08_24
+ */
+static int test_fwid(void)
+{
+ const char *cros_fwid;
+ size_t board_name_length, major_version_length, minor_version_length,
+ sub_minor_version_length;
+ const char *major_version_ptr, *minor_version_ptr,
+ *sub_minor_version_ptr;
+
+ cros_fwid = system_get_cros_fwid(EC_IMAGE_RO);
+
+ TEST_ASSERT(cros_fwid != NULL);
+
+ ccprintf("cros_fwid: %s\n", cros_fwid);
+
+ TEST_LE(strlen(cros_fwid), (size_t)32, "%zu");
+
+ board_name_length = strcspn(cros_fwid, "_");
+ TEST_GE(board_name_length, (size_t)3, "%zu");
+
+ major_version_ptr = cros_fwid + board_name_length + 1;
+ major_version_length = strcspn(major_version_ptr, ".");
+ TEST_GE(major_version_length, (size_t)5, "%zu");
+
+ for (int i = 0; i < major_version_length; i++)
+ TEST_ASSERT(isdigit(major_version_ptr[i]));
+
+ minor_version_ptr = major_version_ptr + major_version_length + 1;
+ minor_version_length = strcspn(minor_version_ptr, ".");
+ TEST_GE(minor_version_length, (size_t)1, "%zu");
+
+ for (int i = 0; i < minor_version_length; i++)
+ TEST_ASSERT(isdigit(minor_version_ptr[i]));
+
+ sub_minor_version_ptr = minor_version_ptr + minor_version_length + 1;
+ sub_minor_version_length = strlen(sub_minor_version_ptr);
+ TEST_GE(sub_minor_version_length, (size_t)1, "%zu");
+
+ for (int i = 0; i < sub_minor_version_length; i++)
+ TEST_ASSERT(isdigit(sub_minor_version_ptr[i]) ||
+ sub_minor_version_ptr[i] == '_');
+
+ return EC_SUCCESS;
+}
+
+/*
+ * Tests requesting TEST.
+ * Example fw version: host_v2.0.10135+b3e38e380c
+ */
+static int test_image_unknown(void)
+{
+ const char *fw_version;
+ const char *cros_fwid;
+
+ fw_version = system_get_version(EC_IMAGE_UNKNOWN);
+
+ TEST_ASSERT(fw_version != NULL);
+ TEST_LE(strlen(fw_version), (size_t)32, "%zu");
+
+ cros_fwid = system_get_cros_fwid(EC_IMAGE_UNKNOWN);
+
+ TEST_ASSERT(cros_fwid != NULL);
+ TEST_LE(strlen(cros_fwid), (size_t)32, "%zu");
+
+ return EC_SUCCESS;
+}
+
+void run_test(int argc, char **argv)
+{
+ RUN_TEST(test_version);
+ RUN_TEST(test_fwid);
+ RUN_TEST(test_image_unknown);
+
+ test_print_result();
+}
diff --git a/test/version.tasklist b/test/version.tasklist
new file mode 100644
index 0000000000..e54ea001bd
--- /dev/null
+++ b/test/version.tasklist
@@ -0,0 +1,9 @@
+/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**
+ * See CONFIG_TASK_LIST in config.h for details.
+ */
+#define CONFIG_TEST_TASK_LIST /* No test task */