662
VERIFY_IS_TRUE(result.Stdout->find(L"options ndots:5 timeout:3") != std::wstring::npos);
663
}
664
665
+ WSLC_TEST_METHOD(WSLCE2E_Container_Create_StopSignal)
666
+ {
667
+ constexpr int ExpectedExitCode = 42;
668
+ auto result = RunWslc(std::format(
669
+ LR"(container create --stop-signal SIGUSR1 --name {} {} bash -c "trap 'exit {}' SIGUSR1; while true; do sleep 1; done")",
670
+ WslcContainerName,
671
+ DebianImage.NameAndTag(),
672
+ ExpectedExitCode));
673
+ result.Verify({.Stderr = L"", .ExitCode = 0});
674
+ const auto containerId = result.GetStdoutOneLine();
675
+ VerifyContainerIsListed(containerId, L"created");
676
+
677
+ result = RunWslc(std::format(L"container start {}", WslcContainerName));
678
+ result.Verify({.Stderr = L"", .ExitCode = 0});
679
+ VerifyContainerIsListed(containerId, L"running");
680
+
681
+ result = RunWslc(std::format(L"container stop {}", WslcContainerName));
682
+ result.Verify({.Stderr = L"", .ExitCode = 0});
683
+
684
+ const auto inspect = InspectContainer(WslcContainerName);
685
+ VERIFY_IS_FALSE(inspect.State.Running);
686
+ VERIFY_ARE_EQUAL(ExpectedExitCode, inspect.State.ExitCode);
687
+ }
688
+
689
+ WSLC_TEST_METHOD(WSLCE2E_Container_Create_ShmSize)
690
+ {
691
+ auto result = RunWslc(
692
+ std::format(L"container create --shm-size 128M --name {} {} df -h /dev/shm", WslcContainerName, DebianImage.NameAndTag()));
693
+ result.Verify({.Stderr = L"", .ExitCode = 0});
694
+
695
+ result = RunWslc(std::format(L"container start -a {}", WslcContainerName));
696
+ result.Verify({.Stderr = L"", .ExitCode = 0});
697
+ VERIFY_IS_TRUE(result.Stdout->find(L"128M") != std::wstring::npos);
698
+ }
699
+
700
+ WSLC_TEST_METHOD(WSLCE2E_Container_Create_ShmSize_Invalid)
701
+ {
702
+ {
703
+ auto result =
704
+ RunWslc(std::format(L"container create --shm-size invalid --name {} {}", WslcContainerName, DebianImage.NameAndTag()));
705
+ result.Verify({.Stderr = L"Invalid shm-size argument value: 'invalid'. Expected a memory size (e.g. 256M, 1G)\r\n", .ExitCode = 1});
706
+ VerifyContainerIsNotListed(WslcContainerName);
707
+ }
708
+
709
+ {
710
+ auto result =
711
+ RunWslc(std::format(L"container create --shm-size 128X --name {} {}", WslcContainerName, DebianImage.NameAndTag()));
712
+ result.Verify({.Stderr = L"Invalid shm-size argument value: '128X'. Expected a memory size (e.g. 256M, 1G)\r\n", .ExitCode = 1});
713
+ VerifyContainerIsNotListed(WslcContainerName);
714
+ }
715
+ }
716
+
717
+ WSLC_TEST_METHOD(WSLCE2E_Container_Create_StopSignal_Invalid)
718
+ {
719
+ {
720
+ auto result = RunWslc(
721
+ std::format(L"container create --stop-signal SIGINVALID --name {} {}", WslcContainerName, DebianImage.NameAndTag()));
722
+ result.Verify({.Stderr = L"Invalid stop-signal value: SIGINVALID is not a recognized signal name or number (Example: SIGKILL, kill, or 9).\r\n", .ExitCode = 1});
723
+ VerifyContainerIsNotListed(WslcContainerName);
724
+ }
725
+
726
+ {
727
+ auto result =
728
+ RunWslc(std::format(L"container create --stop-signal 0 --name {} {}", WslcContainerName, DebianImage.NameAndTag()));
729
+ result.Verify({.Stderr = L"Invalid stop-signal value: 0 is out of valid range (1-31).\r\n", .ExitCode = 1});
730
+ VerifyContainerIsNotListed(WslcContainerName);
731
+ }
732
+
733
+ {
734
+ auto result =
735
+ RunWslc(std::format(L"container create --stop-signal 99 --name {} {}", WslcContainerName, DebianImage.NameAndTag()));
736
+ result.Verify({.Stderr = L"Invalid stop-signal value: 99 is out of valid range (1-31).\r\n", .ExitCode = 1});
737
+ VerifyContainerIsNotListed(WslcContainerName);
738
+ }
739
+ }
740
+
741
private:
742
// Test container name
743
const std::wstring WslcContainerName = L"wslc-test-container";
813
<< L" -P,--publish-all Publish all exposed ports to random host ports\r\n"
814
<< L" --rm Remove the container after it stops\r\n"
815
<< L" --session Specify the session to use\r\n"
816
+ << L" --shm-size Size of /dev/shm (e.g. 64M, 1G)\r\n"
817
+ << L" --stop-signal Signal to stop the container\r\n"
818
<< L" --tmpfs Mount tmpfs to the container at the given path\r\n"
819
<< L" -t,--tty Open a TTY with the container process.\r\n"
820
<< L" -u,--user User ID for the process (name|uid|uid:gid)\r\n"