summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/syscalls/linux/BUILD7
-rw-r--r--test/syscalls/linux/exit.cc1
-rw-r--r--test/syscalls/linux/futex.cc1
-rw-r--r--test/syscalls/linux/proc.cc1
-rw-r--r--test/syscalls/linux/proc_pid_uid_gid_map.cc1
-rw-r--r--test/syscalls/linux/ptrace.cc1
-rw-r--r--test/syscalls/linux/vfork.cc1
-rw-r--r--test/syscalls/linux/wait.cc1
-rw-r--r--test/util/BUILD10
-rw-r--r--test/util/test_util.cc16
-rw-r--r--test/util/test_util.h3
-rw-r--r--test/util/time_util.cc41
-rw-r--r--test/util/time_util.h29
13 files changed, 94 insertions, 19 deletions
diff --git a/test/syscalls/linux/BUILD b/test/syscalls/linux/BUILD
index 014679ec5..750f3a1e2 100644
--- a/test/syscalls/linux/BUILD
+++ b/test/syscalls/linux/BUILD
@@ -638,6 +638,7 @@ cc_binary(
"//test/util:file_descriptor",
"//test/util:test_main",
"//test/util:test_util",
+ "//test/util:time_util",
"@com_google_absl//absl/time",
"@com_google_googletest//:gtest",
],
@@ -815,6 +816,7 @@ cc_binary(
"//test/util:test_main",
"//test/util:test_util",
"//test/util:thread_util",
+ "//test/util:time_util",
"//test/util:timer_util",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/time",
@@ -1410,6 +1412,7 @@ cc_binary(
"//test/util:temp_path",
"//test/util:test_util",
"//test/util:thread_util",
+ "//test/util:time_util",
"//test/util:timer_util",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/synchronization",
@@ -1470,6 +1473,7 @@ cc_binary(
"//test/util:save_util",
"//test/util:test_main",
"//test/util:test_util",
+ "//test/util:time_util",
"@com_google_absl//absl/strings",
"@com_google_googletest//:gtest",
],
@@ -1501,6 +1505,7 @@ cc_binary(
"//test/util:signal_util",
"//test/util:test_util",
"//test/util:thread_util",
+ "//test/util:time_util",
"@com_google_absl//absl/time",
"@com_google_googletest//:gtest",
],
@@ -3161,6 +3166,7 @@ cc_binary(
"//test/util:logging",
"//test/util:multiprocess_util",
"//test/util:test_util",
+ "//test/util:time_util",
"@com_google_absl//absl/time",
"@com_google_googletest//:gtest",
],
@@ -3180,6 +3186,7 @@ cc_binary(
"//test/util:test_main",
"//test/util:test_util",
"//test/util:thread_util",
+ "//test/util:time_util",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/synchronization",
"@com_google_absl//absl/time",
diff --git a/test/syscalls/linux/exit.cc b/test/syscalls/linux/exit.cc
index 99de2b376..d52ea786b 100644
--- a/test/syscalls/linux/exit.cc
+++ b/test/syscalls/linux/exit.cc
@@ -19,6 +19,7 @@
#include "absl/time/time.h"
#include "test/util/file_descriptor.h"
#include "test/util/test_util.h"
+#include "test/util/time_util.h"
namespace gvisor {
namespace testing {
diff --git a/test/syscalls/linux/futex.cc b/test/syscalls/linux/futex.cc
index bfec95466..aacbb5e70 100644
--- a/test/syscalls/linux/futex.cc
+++ b/test/syscalls/linux/futex.cc
@@ -36,6 +36,7 @@
#include "test/util/temp_path.h"
#include "test/util/test_util.h"
#include "test/util/thread_util.h"
+#include "test/util/time_util.h"
#include "test/util/timer_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/proc.cc b/test/syscalls/linux/proc.cc
index d0c3a90b3..e2e8a4ff1 100644
--- a/test/syscalls/linux/proc.cc
+++ b/test/syscalls/linux/proc.cc
@@ -62,6 +62,7 @@
#include "test/util/temp_path.h"
#include "test/util/test_util.h"
#include "test/util/thread_util.h"
+#include "test/util/time_util.h"
#include "test/util/timer_util.h"
// NOTE(magi): No, this isn't really a syscall but this is a really simple
diff --git a/test/syscalls/linux/proc_pid_uid_gid_map.cc b/test/syscalls/linux/proc_pid_uid_gid_map.cc
index df70b7eb9..748f7be58 100644
--- a/test/syscalls/linux/proc_pid_uid_gid_map.cc
+++ b/test/syscalls/linux/proc_pid_uid_gid_map.cc
@@ -37,6 +37,7 @@
#include "test/util/posix_error.h"
#include "test/util/save_util.h"
#include "test/util/test_util.h"
+#include "test/util/time_util.h"
namespace gvisor {
namespace testing {
diff --git a/test/syscalls/linux/ptrace.cc b/test/syscalls/linux/ptrace.cc
index 4c212836c..abf2b1a04 100644
--- a/test/syscalls/linux/ptrace.cc
+++ b/test/syscalls/linux/ptrace.cc
@@ -34,6 +34,7 @@
#include "test/util/signal_util.h"
#include "test/util/test_util.h"
#include "test/util/thread_util.h"
+#include "test/util/time_util.h"
DEFINE_bool(ptrace_test_execve_child, false,
"If true, run the "
diff --git a/test/syscalls/linux/vfork.cc b/test/syscalls/linux/vfork.cc
index 631a53654..f67b06f37 100644
--- a/test/syscalls/linux/vfork.cc
+++ b/test/syscalls/linux/vfork.cc
@@ -26,6 +26,7 @@
#include "test/util/logging.h"
#include "test/util/multiprocess_util.h"
#include "test/util/test_util.h"
+#include "test/util/time_util.h"
DEFINE_bool(vfork_test_child, false,
"If true, run the VforkTest child workload.");
diff --git a/test/syscalls/linux/wait.cc b/test/syscalls/linux/wait.cc
index f413ee6ae..aa27194cb 100644
--- a/test/syscalls/linux/wait.cc
+++ b/test/syscalls/linux/wait.cc
@@ -37,6 +37,7 @@
#include "test/util/signal_util.h"
#include "test/util/test_util.h"
#include "test/util/thread_util.h"
+#include "test/util/time_util.h"
using ::testing::UnorderedElementsAre;
diff --git a/test/util/BUILD b/test/util/BUILD
index a4b47de56..a1b9ff526 100644
--- a/test/util/BUILD
+++ b/test/util/BUILD
@@ -238,6 +238,16 @@ cc_library(
)
cc_library(
+ name = "time_util",
+ testonly = 1,
+ srcs = ["time_util.cc"],
+ hdrs = ["time_util.h"],
+ deps = [
+ "@com_google_absl//absl/time",
+ ],
+)
+
+cc_library(
name = "timer_util",
testonly = 1,
srcs = ["timer_util.cc"],
diff --git a/test/util/test_util.cc b/test/util/test_util.cc
index c52fd9a4a..bf0029951 100644
--- a/test/util/test_util.cc
+++ b/test/util/test_util.cc
@@ -18,7 +18,6 @@
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
-#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/utsname.h>
@@ -211,21 +210,6 @@ std::vector<std::vector<struct iovec>> GenerateIovecs(uint64_t total_size,
return result;
}
-void SleepSafe(absl::Duration duration) {
- if (duration == absl::ZeroDuration()) {
- return;
- }
-
- struct timespec ts = absl::ToTimespec(duration);
- int ret;
- while (1) {
- ret = syscall(__NR_nanosleep, &ts, &ts);
- if (ret == 0 || (ret <= 0 && errno != EINTR)) {
- break;
- }
- }
-}
-
uint64_t Megabytes(uint64_t n) {
// Overflow check, upper 20 bits in n shouldn't be set.
TEST_CHECK(!(0xfffff00000000000 & n));
diff --git a/test/util/test_util.h b/test/util/test_util.h
index 8f5eb5089..cdbe8bfd1 100644
--- a/test/util/test_util.h
+++ b/test/util/test_util.h
@@ -738,9 +738,6 @@ inline PosixErrorOr<float> Atof(absl::string_view str) {
std::vector<std::vector<struct iovec>> GenerateIovecs(uint64_t total_size,
void* buf, size_t buflen);
-// Sleep for at least the specified duration. Avoids glibc.
-void SleepSafe(absl::Duration duration);
-
// Returns bytes in 'n' megabytes. Used for readability.
uint64_t Megabytes(uint64_t n);
diff --git a/test/util/time_util.cc b/test/util/time_util.cc
new file mode 100644
index 000000000..1ddfbfc9c
--- /dev/null
+++ b/test/util/time_util.cc
@@ -0,0 +1,41 @@
+// Copyright 2019 The gVisor Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "test/util/time_util.h"
+
+#include <sys/syscall.h>
+#include <unistd.h>
+
+#include "absl/time/time.h"
+
+namespace gvisor {
+namespace testing {
+
+void SleepSafe(absl::Duration duration) {
+ if (duration == absl::ZeroDuration()) {
+ return;
+ }
+
+ struct timespec ts = absl::ToTimespec(duration);
+ int ret;
+ while (1) {
+ ret = syscall(__NR_nanosleep, &ts, &ts);
+ if (ret == 0 || (ret <= 0 && errno != EINTR)) {
+ break;
+ }
+ }
+}
+
+} // namespace testing
+} // namespace gvisor
diff --git a/test/util/time_util.h b/test/util/time_util.h
new file mode 100644
index 000000000..f3ddc9fde
--- /dev/null
+++ b/test/util/time_util.h
@@ -0,0 +1,29 @@
+// Copyright 2019 The gVisor Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef GVISOR_TEST_UTIL_TIME_UTIL_H_
+#define GVISOR_TEST_UTIL_TIME_UTIL_H_
+
+#include "absl/time/time.h"
+
+namespace gvisor {
+namespace testing {
+
+// Sleep for at least the specified duration. Avoids glibc.
+void SleepSafe(absl::Duration duration);
+
+} // namespace testing
+} // namespace gvisor
+
+#endif // GVISOR_TEST_UTIL_TIME_UTIL_H_