summaryrefslogtreecommitdiffhomepage
path: root/test/util
diff options
context:
space:
mode:
Diffstat (limited to 'test/util')
-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
5 files changed, 80 insertions, 19 deletions
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_