@@ -836,3 +836,69 @@ func copyFile(src, dst string, uid, gid int) error {
836
836
837
837
return nil
838
838
}
839
+
840
+ func TestPID (t * testing.T ) {
841
+ m := & Machine {}
842
+ if _ , err := m .PID (); err == nil {
843
+ t .Errorf ("expected an error, but received none" )
844
+ }
845
+
846
+ var nCpus int64 = 2
847
+ cpuTemplate := models .CPUTemplate (models .CPUTemplateT2 )
848
+ var memSz int64 = 256
849
+ socketPath := filepath .Join (testDataPath , "TestPID.sock" )
850
+ defer os .Remove (socketPath )
851
+
852
+ vmlinuxPath := getVmlinuxPath (t )
853
+
854
+ cfg := Config {
855
+ SocketPath : socketPath ,
856
+ KernelImagePath : vmlinuxPath ,
857
+ MachineCfg : models.MachineConfiguration {
858
+ VcpuCount : Int64 (nCpus ),
859
+ CPUTemplate : cpuTemplate ,
860
+ MemSizeMib : Int64 (memSz ),
861
+ HtEnabled : Bool (false ),
862
+ },
863
+ Drives : []models.Drive {
864
+ models.Drive {
865
+ DriveID : String ("1" ),
866
+ IsRootDevice : Bool (true ),
867
+ IsReadOnly : Bool (false ),
868
+ PathOnHost : String (filepath .Join (testDataPath , "root-drive.img" )),
869
+ },
870
+ },
871
+ Debug : true ,
872
+ DisableValidation : true ,
873
+ }
874
+
875
+ m , err := NewMachine (context .Background (), cfg )
876
+ if err != nil {
877
+ t .Errorf ("expected no error during create machine, but received %v" , err )
878
+ }
879
+
880
+ if err := m .Start (context .Background ()); err != nil {
881
+ t .Errorf ("expected no error during Start, but received %v" , err )
882
+ }
883
+ defer m .StopVMM ()
884
+
885
+ pid , err := m .PID ()
886
+ if err != nil {
887
+ t .Errorf ("unexpected error during PID call, %v" , err )
888
+ }
889
+
890
+ if pid == 0 {
891
+ t .Errorf ("failed to retrieve correct PID" )
892
+ }
893
+
894
+ if err := m .StopVMM (); err != nil {
895
+ t .Errorf ("expected clean kill, but received %v" , err )
896
+ }
897
+
898
+ m .Wait (context .Background ())
899
+
900
+ if _ , err := m .PID (); err == nil {
901
+ t .Errorf ("expected an error, but received none" )
902
+ }
903
+
904
+ }
0 commit comments