Skip to content

Commit

Permalink
[lib/base] Adjust callers of crc32 to use the new location.
Browse files Browse the repository at this point in the history
After moving the CRC32 library out of `silicon_creator`, replace
references to it with the new location and fix include guards and BUILD
files.

Signed-off-by: Jade Philipoom <[email protected]>
  • Loading branch information
jadephilipoom committed Jan 24, 2024
1 parent 93173f3 commit 5a440c2
Show file tree
Hide file tree
Showing 23 changed files with 116 additions and 117 deletions.
71 changes: 70 additions & 1 deletion sw/device/lib/base/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,85 @@
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

load("//rules:cross_platform.bzl", "dual_cc_library", "dual_inputs")
load("//rules:cross_platform.bzl", "dual_cc_device_library_of", "dual_cc_library", "dual_inputs")
load(
"//rules/opentitan:defs.bzl",
"EARLGREY_TEST_ENVS",
"cw310_params",
"opentitan_test",
"verilator_params",
)

package(default_visibility = ["//visibility:public"])

dual_cc_library(
name = "crc32",
srcs = dual_inputs(
device = ["crc32.c"],
host = ["mock_crc32.cc"],
),
hdrs = dual_inputs(
host = ["mock_crc32.h"],
shared = ["crc32.h"],
),
# This library is a dependancy of the ujson library.
visibility = ["//sw/device/lib/ujson:__pkg__"],
deps = dual_inputs(
host = [
":global_mock",
"@googletest//:gtest",
],
shared = [
":memory",
":macros",
],
),
)

cc_test(
name = "crc32_unittest",
srcs = ["crc32_unittest.cc"],
deps = [
dual_cc_device_library_of(":crc32"),
"@googletest//:gtest_main",
],
)

opentitan_test(
name = "crc32_functest",
srcs = ["crc32_functest.c"],
exec_env = EARLGREY_TEST_ENVS,
verilator = verilator_params(
timeout = "long",
),
deps = [
":crc32",
"//sw/device/lib/testing/test_framework:ottf_main",
],
)

opentitan_test(
name = "crc32_perftest",
srcs = ["crc32_perftest.c"],
cw310 = cw310_params(
tags = [
"manual",
],
),
exec_env = {
"//hw/top_earlgrey:fpga_cw310_test_rom": None,
},
deps = [
":crc32",
":macros",
"//sw/device/lib/runtime:ibex",
"//sw/device/lib/runtime:log",
"//sw/device/lib/testing/test_framework:check",
"//sw/device/lib/testing/test_framework:ottf_main",
"//sw/device/lib/testing/test_framework:ottf_test_config",
],
)

cc_library(
name = "global_mock",
hdrs = ["global_mock.h"],
Expand Down
2 changes: 1 addition & 1 deletion sw/device/lib/base/crc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#include "sw/device/silicon_creator/lib/crc32.h"
#include "sw/device/lib/base/crc32.h"

#include <stdbool.h>

Expand Down
6 changes: 3 additions & 3 deletions sw/device/lib/base/crc32.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#ifndef OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_CRC32_H_
#define OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_CRC32_H_
#ifndef OPENTITAN_SW_DEVICE_LIB_BASE_CRC32_H_
#define OPENTITAN_SW_DEVICE_LIB_BASE_CRC32_H_

#include <stddef.h>
#include <stdint.h>
Expand Down Expand Up @@ -72,4 +72,4 @@ uint32_t crc32(const void *buf, size_t len);
} // extern "C"
#endif // __cplusplus

#endif // OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_CRC32_H_
#endif // OPENTITAN_SW_DEVICE_LIB_BASE_CRC32_H_
37 changes: 18 additions & 19 deletions sw/device/lib/base/crc32_functest.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#include "sw/device/lib/base/crc32.h"
#include "sw/device/lib/base/macros.h"
#include "sw/device/lib/testing/test_framework/check.h"
#include "sw/device/lib/testing/test_framework/ottf_main.h"
#include "sw/device/lib/testing/test_framework/ottf_test_config.h"
#include "sw/device/silicon_creator/lib/crc32.h"
#include "sw/device/silicon_creator/lib/error.h"

#define LOG_TEST_PARAMS(x) \
LOG_INFO("[%s] Test params: input = 0x%!y, expected_crc32 = 0x%x", \
Expand Down Expand Up @@ -40,53 +39,53 @@ static const test_params_t kTestCases[] = {{
0x9508ac14,
}};

static rom_error_t crc32_test(void) {
static status_t crc32_test(void) {
for (size_t i = 0; i < ARRAYSIZE(kTestCases); ++i) {
LOG_TEST_PARAMS(kTestCases[i]);
CHECK(crc32(kTestCases[i].input, kTestCases[i].input_len) ==
kTestCases[i].expected_crc32);
TRY_CHECK(crc32(kTestCases[i].input, kTestCases[i].input_len) ==
kTestCases[i].expected_crc32);
}
return kErrorOk;
return OK_STATUS();
}

static rom_error_t crc32_add_test(void) {
static status_t crc32_add_test(void) {
for (size_t i = 0; i < ARRAYSIZE(kTestCases); ++i) {
LOG_TEST_PARAMS(kTestCases[i]);
uint32_t ctx;
crc32_init(&ctx);
crc32_add(&ctx, kTestCases[i].input, kTestCases[i].input_len);
CHECK(crc32_finish(&ctx) == kTestCases[i].expected_crc32);
TRY_CHECK(crc32_finish(&ctx) == kTestCases[i].expected_crc32);
}
return kErrorOk;
return OK_STATUS();
}

static rom_error_t crc32_misaligned_test(void) {
static status_t crc32_misaligned_test(void) {
uint32_t kExpCrc = 0x414fa339;
alignas(uint32_t) char input[] =
">The quick brown fox jumps over the lazy dog";
CHECK(crc32(&input[1], sizeof(input) - 2) == kExpCrc);
TRY_CHECK(crc32(&input[1], sizeof(input) - 2) == kExpCrc);

uint32_t ctx;
crc32_init(&ctx);
crc32_add(&ctx, &input[1], sizeof(input) - 2);
CHECK(crc32_finish(&ctx) == kExpCrc);
return kErrorOk;
TRY_CHECK(crc32_finish(&ctx) == kExpCrc);
return OK_STATUS();
}

static rom_error_t crc32_add8_test(void) {
static status_t crc32_add8_test(void) {
for (size_t i = 0; i < ARRAYSIZE(kTestCases); ++i) {
LOG_TEST_PARAMS(kTestCases[i]);
uint32_t ctx;
crc32_init(&ctx);
for (size_t j = 0; j < kTestCases[i].input_len; ++j) {
crc32_add8(&ctx, kTestCases[i].input[j]);
}
CHECK(crc32_finish(&ctx) == kTestCases[i].expected_crc32);
TRY_CHECK(crc32_finish(&ctx) == kTestCases[i].expected_crc32);
}
return kErrorOk;
return OK_STATUS();
}

static rom_error_t crc32_add32_test(void) {
static status_t crc32_add32_test(void) {
uint32_t ctx;
crc32_init(&ctx);
const uint32_t kExpCrc = 0x9508ac14;
Expand All @@ -95,8 +94,8 @@ static rom_error_t crc32_add32_test(void) {
OT_DISCARD(crc32_finish(&ctx));
crc32_add32(&ctx, 0x1badb002);

CHECK(crc32_finish(&ctx) == kExpCrc);
return kErrorOk;
TRY_CHECK(crc32_finish(&ctx) == kExpCrc);
return OK_STATUS();
}

OTTF_DEFINE_TEST_CONFIG();
Expand Down
2 changes: 1 addition & 1 deletion sw/device/lib/base/crc32_perftest.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
#include <stdbool.h>
#include <stdint.h>

#include "sw/device/lib/base/crc32.h"
#include "sw/device/lib/base/macros.h"
#include "sw/device/lib/runtime/ibex.h"
#include "sw/device/lib/runtime/log.h"
#include "sw/device/lib/testing/test_framework/check.h"
#include "sw/device/lib/testing/test_framework/ottf_main.h"
#include "sw/device/lib/testing/test_framework/ottf_test_config.h"
#include "sw/device/silicon_creator/lib/crc32.h"

OTTF_DEFINE_TEST_CONFIG();

Expand Down
2 changes: 1 addition & 1 deletion sw/device/lib/base/crc32_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#include "sw/device/silicon_creator/lib/crc32.h"
#include "sw/device/lib/base/crc32.h"

#include <cstring>
#include <stdint.h>
Expand Down
2 changes: 1 addition & 1 deletion sw/device/lib/base/mock_crc32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#include "sw/device/silicon_creator/lib/mock_crc32.h"
#include "sw/device/lib/base/mock_crc32.h"

namespace rom_test {
extern "C" {
Expand Down
8 changes: 4 additions & 4 deletions sw/device/lib/base/mock_crc32.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#ifndef OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_MOCK_CRC32_H_
#define OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_MOCK_CRC32_H_
#ifndef OPENTITAN_SW_DEVICE_LIB_BASE_MOCK_CRC32_H_
#define OPENTITAN_SW_DEVICE_LIB_BASE_MOCK_CRC32_H_

#include "sw/device/lib/base/crc32.h"
#include "sw/device/lib/base/global_mock.h"
#include "sw/device/silicon_creator/lib/crc32.h"

namespace rom_test {
namespace internal {
Expand All @@ -30,4 +30,4 @@ using MockCrc32 = testing::StrictMock<internal::MockCrc32>;

} // namespace rom_test

#endif // OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_MOCK_CRC32_H_
#endif // OPENTITAN_SW_DEVICE_LIB_BASE_MOCK_CRC32_H_
2 changes: 1 addition & 1 deletion sw/device/lib/testing/test_framework/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ cc_library(
hdrs = ["coverage.h"],
linkopts = ["-lgcc"],
deps = [
"//sw/device/lib/base:crc32",
"//sw/device/lib/base:memory",
"//sw/device/lib/runtime:log",
"//sw/device/lib/runtime:print",
"//sw/device/silicon_creator/lib:crc32",
"//third_party/llvm_compiler_rt",
],
)
Expand Down
2 changes: 1 addition & 1 deletion sw/device/lib/testing/test_framework/coverage_llvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#include <stdint.h>

#include "external/llvm_compiler_rt/lib/profile/InstrProfiling.h"
#include "sw/device/lib/base/crc32.h"
#include "sw/device/lib/runtime/log.h"
#include "sw/device/lib/runtime/print.h"
#include "sw/device/lib/testing/test_framework/coverage.h"
#include "sw/device/silicon_creator/lib/crc32.h"

/**
* When the linker finds a definition of this symbol, it knows to skip loading
Expand Down
2 changes: 1 addition & 1 deletion sw/device/lib/ujson/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cc_library(
"//sw/device/lib/base:math",
"//sw/device/lib/base:status",
"//sw/device/lib/runtime:print",
dual_cc_device_library_of("//sw/device/silicon_creator/lib:crc32"),
dual_cc_device_library_of("//sw/device/lib/base:crc32"),
],
)

Expand Down
2 changes: 1 addition & 1 deletion sw/device/lib/ujson/example_roundtrip.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include <stdlib.h>
#include <string.h>

#include "sw/device/lib/base/crc32.h"
#include "sw/device/lib/base/status.h"
#include "sw/device/lib/ujson/example.h"
#include "sw/device/silicon_creator/lib/crc32.h"

status_t stdio_getc(void *context) {
int ch = fgetc(stdin);
Expand Down
2 changes: 1 addition & 1 deletion sw/device/lib/ujson/ujson.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
#include <stdint.h>
#include <string.h>

#include "sw/device/lib/base/crc32.h"
#include "sw/device/lib/base/math.h"
#include "sw/device/lib/base/status.h"
#include "sw/device/lib/runtime/print.h"
#include "sw/device/lib/ujson/private_status.h"
#include "sw/device/silicon_creator/lib/crc32.h"

static bool is_space(int c) { return c == ' ' || (unsigned)c - '\t' < 5; }

Expand Down
69 changes: 0 additions & 69 deletions sw/device/silicon_creator/lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -373,75 +373,6 @@ cc_test(
],
)

dual_cc_library(
name = "crc32",
srcs = dual_inputs(
device = ["crc32.c"],
host = ["mock_crc32.cc"],
),
hdrs = dual_inputs(
host = ["mock_crc32.h"],
shared = ["crc32.h"],
),
# This library is a dependancy of the ujson library.
visibility = ["//sw/device/lib/ujson:__pkg__"],
deps = dual_inputs(
host = [
"//sw/device/lib/base:global_mock",
"@googletest//:gtest",
],
shared = [
"//sw/device/lib/base:memory",
"//sw/device/lib/base:macros",
],
),
)

cc_test(
name = "crc32_unittest",
srcs = ["crc32_unittest.cc"],
deps = [
dual_cc_device_library_of(":crc32"),
"//sw/device/silicon_creator/testing:rom_test",
"@googletest//:gtest_main",
],
)

opentitan_test(
name = "crc32_functest",
srcs = ["crc32_functest.c"],
exec_env = EARLGREY_TEST_ENVS,
verilator = verilator_params(
timeout = "long",
),
deps = [
":crc32",
"//sw/device/lib/testing/test_framework:ottf_main",
],
)

opentitan_test(
name = "crc32_perftest",
srcs = ["crc32_perftest.c"],
cw310 = cw310_params(
tags = [
"manual",
],
),
exec_env = {
"//hw/top_earlgrey:fpga_cw310_test_rom": None,
},
deps = [
":crc32",
"//sw/device/lib/base:macros",
"//sw/device/lib/runtime:ibex",
"//sw/device/lib/runtime:log",
"//sw/device/lib/testing/test_framework:check",
"//sw/device/lib/testing/test_framework:ottf_main",
"//sw/device/lib/testing/test_framework:ottf_test_config",
],
)

cc_library(
name = "bootstrap",
srcs = ["bootstrap.c"],
Expand Down
Loading

0 comments on commit 5a440c2

Please sign in to comment.