util: Break up some unit tests in the m5 utility.

Some unit tests for the inst and semi call types in the m5 utility were
too big and testing multiple scenarioes. This change breaks them up into
individual tests, like in the addr call type unit test.

Change-Id: I764d9edfbe4f6bdcc5907173247f7511c68aa1d0
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/36855
Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Gabe Black
2020-10-30 21:19:30 -07:00
parent c110695a44
commit 99d96b76cb
2 changed files with 79 additions and 47 deletions

View File

@@ -58,24 +58,34 @@ class DefaultCallType : public CallType
DefaultCallType defaultCallType;
TEST(InstCallType, Detect)
class InstCallTypeTest : public testing::Test
{
CallType *ct;
protected:
CallType *ct = nullptr;
};
TEST_F(InstCallTypeTest, EmptyArgs)
{
// Inst should not be selected if there are no arguments.
Args empty({});
defaultCallType.init_called = false;
ct = CallType::detect(empty);
EXPECT_EQ(ct, &defaultCallType);
EXPECT_TRUE(defaultCallType.init_called);
}
TEST_F(InstCallTypeTest, NotAnyArg)
{
// Inst should not be selected if --inst isn't the first argument.
Args one_arg({"one"});
defaultCallType.init_called = false;
ct = CallType::detect(one_arg);
EXPECT_EQ(ct, &defaultCallType);
EXPECT_TRUE(defaultCallType.init_called);
}
TEST_F(InstCallTypeTest, FirstArg)
{
// Inst should be selected if --inst is the first argument.
Args selected({"--inst"});
defaultCallType.init_called = false;
@@ -83,14 +93,20 @@ TEST(InstCallType, Detect)
EXPECT_NE(ct, &defaultCallType);
EXPECT_NE(ct, nullptr);
EXPECT_FALSE(defaultCallType.init_called);
}
TEST_F(InstCallTypeTest, ExtraArg)
{
Args extra({"--inst", "foo"});
defaultCallType.init_called = false;
ct = CallType::detect(extra);
EXPECT_NE(ct, &defaultCallType);
EXPECT_NE(ct, nullptr);
EXPECT_FALSE(defaultCallType.init_called);
}
TEST_F(InstCallTypeTest, NotFirstArg)
{
// Inst should not be selected if --inst isn't first.
Args not_first({"foo", "--inst"});
defaultCallType.init_called = false;
@@ -103,7 +119,7 @@ sigjmp_buf interceptEnv;
siginfo_t interceptSiginfo;
void
sigill_handler(int sig, siginfo_t *info, void *ucontext)
sigillHandler(int sig, siginfo_t *info, void *ucontext)
{
std::memcpy(&interceptSiginfo, info, sizeof(interceptSiginfo));
siglongjmp(interceptEnv, 1);
@@ -138,7 +154,7 @@ TEST(InstCallType, Sum)
struct sigaction sigill_action;
std::memset(&sigill_action, 0, sizeof(sigill_action));
sigill_action.sa_sigaction = &sigill_handler;
sigill_action.sa_sigaction = &sigillHandler;
sigill_action.sa_flags = SA_SIGINFO | SA_RESETHAND;
struct sigaction old_sigill_action;

View File

@@ -54,57 +54,73 @@ class DefaultCallType : public CallType
const DispatchTable &getDispatch() const override { return dt; }
};
DefaultCallType default_call_type;
DefaultCallType defaultCallType;
TEST(SemiCallType, Detect)
class SemiCallTypeTest : public testing::Test
{
CallType *ct;
protected:
CallType *ct = nullptr;
};
TEST_F(SemiCallTypeTest, EmptyArgs)
{
// Semi should not be selected if there are no arguments.
Args empty({});
default_call_type.init_called = false;
defaultCallType.init_called = false;
ct = CallType::detect(empty);
EXPECT_EQ(ct, &default_call_type);
EXPECT_TRUE(default_call_type.init_called);
// Inst should not be selected if --semi isn't the first argument.
Args one_arg({"one"});
default_call_type.init_called = false;
ct = CallType::detect(one_arg);
EXPECT_EQ(ct, &default_call_type);
EXPECT_TRUE(default_call_type.init_called);
// Semi should be selected if --semi is the first argument.
Args selected({"--semi"});
default_call_type.init_called = false;
ct = CallType::detect(selected);
EXPECT_NE(ct, &default_call_type);
EXPECT_NE(ct, nullptr);
EXPECT_FALSE(default_call_type.init_called);
Args extra({"--semi", "foo"});
default_call_type.init_called = false;
ct = CallType::detect(extra);
EXPECT_NE(ct, &default_call_type);
EXPECT_NE(ct, nullptr);
EXPECT_FALSE(default_call_type.init_called);
// Semi should not be selected if --semi isn't first.
Args not_first({"foo", "--semi"});
default_call_type.init_called = false;
ct = CallType::detect(not_first);
EXPECT_EQ(ct, &default_call_type);
EXPECT_TRUE(default_call_type.init_called);
EXPECT_EQ(ct, &defaultCallType);
EXPECT_TRUE(defaultCallType.init_called);
}
sigjmp_buf intercept_env;
siginfo_t intercept_siginfo;
TEST_F(SemiCallTypeTest, NotAnyArg)
{
// Inst should not be selected if --semi isn't the first argument.
Args one_arg({"one"});
defaultCallType.init_called = false;
ct = CallType::detect(one_arg);
EXPECT_EQ(ct, &defaultCallType);
EXPECT_TRUE(defaultCallType.init_called);
}
TEST_F(SemiCallTypeTest, FirstArg)
{
// Semi should be selected if --semi is the first argument.
Args selected({"--semi"});
defaultCallType.init_called = false;
ct = CallType::detect(selected);
EXPECT_NE(ct, &defaultCallType);
EXPECT_NE(ct, nullptr);
EXPECT_FALSE(defaultCallType.init_called);
}
TEST_F(SemiCallTypeTest, ExtraArg)
{
Args extra({"--semi", "foo"});
defaultCallType.init_called = false;
ct = CallType::detect(extra);
EXPECT_NE(ct, &defaultCallType);
EXPECT_NE(ct, nullptr);
EXPECT_FALSE(defaultCallType.init_called);
}
TEST_F(SemiCallTypeTest, NotFirstArg)
{
// Semi should not be selected if --semi isn't first.
Args not_first({"foo", "--semi"});
defaultCallType.init_called = false;
ct = CallType::detect(not_first);
EXPECT_EQ(ct, &defaultCallType);
EXPECT_TRUE(defaultCallType.init_called);
}
sigjmp_buf interceptEnv;
siginfo_t interceptSiginfo;
void
sigill_handler(int sig, siginfo_t *info, void *ucontext)
sigillHandler(int sig, siginfo_t *info, void *ucontext)
{
std::memcpy(&intercept_siginfo, info, sizeof(intercept_siginfo));
siglongjmp(intercept_env, 1);
std::memcpy(&interceptSiginfo, info, sizeof(interceptSiginfo));
siglongjmp(interceptEnv, 1);
}
TEST(SemiCallType, Sum)
@@ -136,14 +152,14 @@ TEST(SemiCallType, Sum)
struct sigaction sigill_action;
std::memset(&sigill_action, 0, sizeof(sigill_action));
sigill_action.sa_sigaction = &sigill_handler;
sigill_action.sa_sigaction = &sigillHandler;
sigill_action.sa_flags = SA_SIGINFO | SA_RESETHAND;
struct sigaction old_sigill_action;
sigaction(SIGILL, &sigill_action, &old_sigill_action);
if (!sigsetjmp(intercept_env, 1)) {
if (!sigsetjmp(interceptEnv, 1)) {
(*dt.m5_sum)(2, 2, 0, 0, 0, 0);
sigaction(SIGILL, &old_sigill_action, nullptr);
ADD_FAILURE() << "Didn't die when attempting to run \"sum\".";
@@ -151,7 +167,7 @@ TEST(SemiCallType, Sum)
}
// Back from siglongjump.
auto &info = intercept_siginfo;
auto &info = interceptSiginfo;
EXPECT_EQ(info.si_signo, SIGILL);
EXPECT_TRUE(info.si_code == ILL_ILLOPC || info.si_code == ILL_ILLOPN);