Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3867)

Unified Diff: sandbox/linux/seccomp-bpf/sandbox_bpf_unittest.cc

Issue 10833044: Refactored ErrorCode into it's own class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added unittest (and new framework to make this possible) Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sandbox/linux/seccomp-bpf/sandbox_bpf_unittest.cc
diff --git a/sandbox/linux/seccomp-bpf/sandbox_bpf_unittest.cc b/sandbox/linux/seccomp-bpf/sandbox_bpf_unittest.cc
index 54fe7a7bff7bec3748b7a3a4c54eddb007724f07..bf26b11de646486f99c4f2fa96f2e52e39cc0270 100644
--- a/sandbox/linux/seccomp-bpf/sandbox_bpf_unittest.cc
+++ b/sandbox/linux/seccomp-bpf/sandbox_bpf_unittest.cc
@@ -78,8 +78,8 @@ void StartSandboxOrDie(Sandbox::EvaluateSyscall evaluator) {
void RunInSandbox(Sandbox::EvaluateSyscall evaluator,
void (*SandboxedCode)()) {
- // TODO(markus): Implement IsEqual for ErrorCode
- // IsEqual(evaluator(__NR_exit_group), Sandbox::SB_ALLOWED) <<
+ // TODO(jln): Implement IsEqual for ErrorCode
+ // IsEqual(evaluator(__NR_exit_group), ErrorCode::ERR_ALLOWED) <<
// "You need to always allow exit_group() in your test policy";
StartSandboxOrDie(evaluator);
// TODO(jln): find a way to use the testing framework inside
@@ -110,17 +110,17 @@ void TryPolicyInProcess(Sandbox::EvaluateSyscall evaluator,
// A simple blacklist test
-Sandbox::ErrorCode BlacklistNanosleepPolicy(int sysno) {
+ErrorCode BlacklistNanosleepPolicy(int sysno) {
if (sysno < static_cast<int>(MIN_SYSCALL) ||
sysno > static_cast<int>(MAX_SYSCALL)) {
// FIXME: we should really not have to do that in a trivial policy
- return ENOSYS;
+ return ErrorCode(ENOSYS);
}
switch (sysno) {
case __NR_nanosleep:
- return EACCES;
+ return ErrorCode(EACCES);
default:
- return Sandbox::SB_ALLOWED;
+ return ErrorCode(ErrorCode::ERR_ALLOWED);
}
}
@@ -139,13 +139,13 @@ TEST(SandboxBpf, ApplyBasicBlacklistPolicy) {
// Now do a simple whitelist test
-Sandbox::ErrorCode WhitelistGetpidPolicy(int sysno) {
+ErrorCode WhitelistGetpidPolicy(int sysno) {
switch (sysno) {
case __NR_getpid:
case __NR_exit_group:
- return Sandbox::SB_ALLOWED;
+ return ErrorCode(ErrorCode::ERR_ALLOWED);
default:
- return ENOMEM;
+ return ErrorCode(ENOMEM);
}
}
@@ -179,18 +179,18 @@ intptr_t EnomemHandler(const struct arch_seccomp_data& args, void *aux) {
return -ENOMEM;
}
-Sandbox::ErrorCode BlacklistNanosleepPolicySigsys(int sysno) {
+ErrorCode BlacklistNanosleepPolicySigsys(int sysno) {
if (sysno < static_cast<int>(MIN_SYSCALL) ||
sysno > static_cast<int>(MAX_SYSCALL)) {
// FIXME: we should really not have to do that in a trivial policy
- return ENOSYS;
+ return ErrorCode(ENOSYS);
}
switch (sysno) {
case __NR_nanosleep:
- return Sandbox::ErrorCode(EnomemHandler,
+ return Sandbox::Trap(EnomemHandler,
static_cast<void *>(&BlacklistNanosleepPolicySigsysAuxData));
default:
- return Sandbox::SB_ALLOWED;
+ return ErrorCode(ErrorCode::ERR_ALLOWED);
}
}
@@ -231,11 +231,11 @@ int SysnoToRandomErrno(int sysno) {
return ((sysno & ~3) >> 2) % 29 + 1;
}
-Sandbox::ErrorCode SyntheticPolicy(int sysno) {
+ErrorCode SyntheticPolicy(int sysno) {
if (sysno < static_cast<int>(MIN_SYSCALL) ||
sysno > static_cast<int>(MAX_SYSCALL)) {
// FIXME: we should really not have to do that in a trivial policy.
- return ENOSYS;
+ return ErrorCode(ENOSYS);
}
// TODO(jorgelo): remove this restriction once crbug.com/141694 is fixed.
@@ -246,9 +246,9 @@ Sandbox::ErrorCode SyntheticPolicy(int sysno) {
if (sysno == __NR_exit_group) {
// exit_group() is special, we really need it to work.
- return Sandbox::SB_ALLOWED;
+ return ErrorCode(ErrorCode::ERR_ALLOWED);
} else {
- return SysnoToRandomErrno(sysno);
+ return ErrorCode(SysnoToRandomErrno(sysno));
}
}

Powered by Google App Engine
This is Rietveld 408576698