diff options
author | Jack Lloyd <[email protected]> | 2017-12-06 05:31:48 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-12-06 05:31:48 -0500 |
commit | 5d101ca94e2a53ebd9313d35669320e87835c618 (patch) | |
tree | fc417e0d55e5e3f1c5c9599c94f79d68fe8fd06c | |
parent | 9036321248e152f0c233af0a1241bbef894c1203 (diff) |
Add some basic tests of CPUID class
-rw-r--r-- | src/tests/test_utils.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/tests/test_utils.cpp b/src/tests/test_utils.cpp index 3c4accab2..c17acac57 100644 --- a/src/tests/test_utils.cpp +++ b/src/tests/test_utils.cpp @@ -547,6 +547,50 @@ class Hostname_Tests final : public Text_Based_Test BOTAN_REGISTER_TEST("hostname", Hostname_Tests); +class CPUID_Tests final : public Test + { + public: + + std::vector<Test::Result> run() override + { + Test::Result result("CPUID"); + + result.confirm("Endian is either little or big", + Botan::CPUID::is_big_endian() || Botan::CPUID::is_little_endian()); + + if(Botan::CPUID::is_little_endian()) + { + result.test_eq("If endian is little, it is not also big endian", Botan::CPUID::is_big_endian(), false); + } + else + { + result.test_eq("If endian is big, it is not also little endian", Botan::CPUID::is_little_endian(), false); + } + + const std::string cpuid_string = Botan::CPUID::to_string(); + result.test_success("CPUID::to_string doesn't crash"); + +#if defined(BOTAN_TARGET_CPU_IS_X86_FAMILY) + + if(Botan::CPUID::has_sse2()) + { + result.confirm("Output string includes sse2", cpuid_string.find("sse2") != std::string::npos); + + Botan::CPUID::clear_cpuid_bit(Botan::CPUID::CPUID_SSE2_BIT); + + result.test_eq("After clearing cpuid bit, has_sse2 returns false", Botan::CPUID::has_sse2(), false); + + Botan::CPUID::initialize(); // reset state + result.test_eq("After reinitializing, has_sse2 returns true", Botan::CPUID::has_sse2(), true); + } +#endif + + return {result}; + } + }; + +BOTAN_REGISTER_TEST("cpuid", CPUID_Tests); + } } |