summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRob Barnes <robbarnes@google.com>2021-05-13 12:27:56 -0600
committerCommit Bot <commit-bot@chromium.org>2021-09-14 12:18:02 +0000
commit5d157c8679880b8c86bb3944daa35ba25aece58b (patch)
treec8285384008e6ee38b16d88e13f8f258298f3808 /test
parentda4711d25c547f760efd1b2e8df1af2957972eae (diff)
downloadchrome-ec-5d157c8679880b8c86bb3944daa35ba25aece58b.tar.gz
system: Add CrOS FWID to version output
EC version does not follow the the AP and OS version. This causes confusion during development. This change augments the EC version output to include the CrOS FWID when available. The CrOS FWID will be missing when the CrOS EC is built outside of cros_sdk. When CrOS FWID is missing 'CROS_FWID_MISSING' will be used. Zephyr/zmake support will be added later, CROS_FWID32 is set to 'CROS_FWID_MISSING' in zephyr builds until then. BUG=b:188073399 TEST=version 21-05-20 16:43:18.627 Chip: Nuvoton NPCX993F A.00160101 21-05-20 16:43:18.631 Board: 1 21-05-20 16:43:18.631 RO: guybrush_v2.0.8770+f47439f75 21-05-20 16:43:18.634 guybrush_13983.0.21_05_20 21-05-20 16:43:18.639 RW_A: * guybrush_v2.0.8770+f47439f75 21-05-20 16:43:18.641 * guybrush_13983.0.21_05_20 21-05-20 16:43:18.644 RW_B: guybrush_v2.0.8770+f47439f75 21-05-20 16:43:18.644 guybrush_13983.0.21_05_20 21-05-20 16:43:18.647 Build: guybrush_v2.0.8770+f47439f75 21-05-20 16:43:18.651 guybrush_13983.0.21_05_20 2021-05-20 21-05-20 16:43:18.657 16:31:19 robbarnes@robbarnes0 ectool version RO version: guybrush_v2.0.8770+f47439f75 RO cros fwid: guybrush_13983.0.21_05_20 RW version: guybrush_v2.0.8770+f47439f75 RW cros fwid: guybrush_13983.0.21_05_20 Firmware copy: RO Build info: guybrush_v2.0.8770+f47439f75 guybrush_13983.0.21_05_20 2021-05-20 16:31:19 robbarnes@robbarnes0 Tool version: 1.1.9999-f47439f @robbarnes0 BRANCH=None Signed-off-by: Rob Barnes <robbarnes@google.com> Change-Id: Ief0a0c6e9d35edc72ac2d4780ee203be41d7305f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2894145 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
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 */