tests: add several timens tests

These are not exhaustive, but at least confirm that the feature is not
obviously broken (we correctly set the time offsets).

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
This commit is contained in:
Aleksa Sarai
2023-08-10 18:55:11 +10:00
parent 9acfd7b1a3
commit aa5f4c1137
3 changed files with 95 additions and 0 deletions
@@ -6,6 +6,7 @@ import (
"testing"
"github.com/opencontainers/runc/libcontainer/configs"
"github.com/opencontainers/runtime-spec/specs-go"
"golang.org/x/sys/unix"
)
@@ -201,6 +202,40 @@ func TestValidateUsernamespaceWithoutUserNS(t *testing.T) {
}
}
func TestValidateTimeNamespace(t *testing.T) {
if _, err := os.Stat("/proc/self/ns/time"); os.IsNotExist(err) {
t.Skip("Test requires timens.")
}
config := &configs.Config{
Rootfs: "/var",
Namespaces: configs.Namespaces(
[]configs.Namespace{
{Type: configs.NEWTIME},
},
),
}
err := Validate(config)
if err != nil {
t.Errorf("expected error to not occur %+v", err)
}
}
func TestValidateTimeOffsetsWithoutTimeNamespace(t *testing.T) {
config := &configs.Config{
Rootfs: "/var",
TimeOffsets: map[string]specs.LinuxTimeOffset{
"boottime": {Secs: 150, Nanosecs: 314159},
"monotonic": {Secs: 512, Nanosecs: 271818},
},
}
err := Validate(config)
if err == nil {
t.Error("Expected error to occur but it was nil")
}
}
// TestConvertSysctlVariableToDotsSeparator tests whether the sysctl variable
// can be correctly converted to a dot as a separator.
func TestConvertSysctlVariableToDotsSeparator(t *testing.T) {