Chromium Code Reviews| Index: components/nacl/loader/nonsfi/nonsfi_sandbox_unittest.cc |
| diff --git a/components/nacl/loader/nonsfi/nonsfi_sandbox_unittest.cc b/components/nacl/loader/nonsfi/nonsfi_sandbox_unittest.cc |
| index febbcd927057d65610c5624915b6fb740e79af44..fff8ed22093e5b284d725ebf3fb75ccfa80703a2 100644 |
| --- a/components/nacl/loader/nonsfi/nonsfi_sandbox_unittest.cc |
| +++ b/components/nacl/loader/nonsfi/nonsfi_sandbox_unittest.cc |
| @@ -22,6 +22,7 @@ |
| #include <sys/syscall.h> |
| #include <sys/types.h> |
| #include <sys/wait.h> |
| +#include <time.h> |
| #include <unistd.h> |
| #include "base/bind.h" |
| @@ -391,6 +392,42 @@ BPF_TEST_C(NaClNonSfiSandboxTest, |
| BPF_ASSERT_EQ(ENOMEM, errno); |
| } |
| +BPF_TEST_C(NaClNonSfiSandboxTest, |
| + clock_gettime_allowed, |
| + nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
| + struct timespec ts; |
| + BPF_ASSERT_EQ(0, clock_gettime(CLOCK_MONOTONIC, &ts)); |
|
hamaji
2014/05/19 05:54:11
Maybe better to check if |ts| is filled.
mdempsky
2014/05/19 06:59:22
Done.
|
| + BPF_ASSERT_EQ(0, clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts)); |
| + BPF_ASSERT_EQ(0, clock_gettime(CLOCK_REALTIME, &ts)); |
| + BPF_ASSERT_EQ(0, clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts)); |
| +} |
| + |
| +class ClockGetTimeCrashCPUClockDelegate : public sandbox::BPFTesterDelegate { |
|
hamaji
2014/05/19 05:54:11
Could you add a brief comment to explain why we ne
mdempsky
2014/05/19 06:59:22
Done.
|
| + public: |
| + ClockGetTimeCrashCPUClockDelegate() { |
| + const pid_t kInitPID = 1; |
| + CHECK_EQ(0, clock_getcpuclockid(kInitPID, &init_clock_id_)); |
| + } |
| + |
| + virtual scoped_ptr<sandbox::SandboxBPFPolicy> GetSandboxBPFPolicy() OVERRIDE { |
| + return scoped_ptr<sandbox::SandboxBPFPolicy>( |
| + new nacl::nonsfi::NaClNonSfiBPFSandboxPolicy); |
| + } |
| + |
| + virtual void RunTestFunction() OVERRIDE { |
| + struct timespec ts; |
| + clock_gettime(init_clock_id_, &ts); |
| + } |
| + |
| + private: |
| + clockid_t init_clock_id_; |
| +}; |
| + |
| +BPF_DEATH_TEST_D(NaClNonSfiSandboxTest, |
| + clock_gettime_crash_cpu_clock, |
| + DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), |
| + ClockGetTimeCrashCPUClockDelegate); |
|
hamaji
2014/05/19 05:54:11
I think you can also test CLOCK_MONOTONIC_RAW
mdempsky
2014/05/19 06:59:22
Done.
|
| + |
| // The following test cases check if syscalls return EPERM regardless |
| // of arguments. |
| #define RESTRICT_SYSCALL_EPERM_TEST(name) \ |