Add the new tool for create GVT-g Linux guest based on KVMGT
PATCH v2 1/1 Add the new tool for create GVT-g Linux guest based on KVMGT
GVT-g (Intel® Graphics Virtualization Technology) is a full GPU virtualization solution with mediated pass-through support.
This tool is for create basic Linux guest based on KVMGT with VFIO framework, it including create vgpu, create guest, check IP address, destroy guest, remove vgpu,check dmesg log, etc functions.
v2: Treat this case as a free-standing tool, with detect & skip when it's not running on GVT-g capable platform or running without the required tools.
--- tools/Makefile.sources | 1 + tools/intel_gvtg_test.c | 355 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 356 insertions(+) create mode 100644 tools/intel_gvtg_test.c
tools/Makefile.sources +1 -0
@@ -30,6 +30,7 @@ tools_prog_lists = \ intel_stepping \ intel_watermark \ intel_gem_info \ + intel_gvtg_test \ $(NULL) dist_bin_SCRIPTS = intel_gpu_abrt
tools/intel_gvtg_test.c new file +355 -0
355 lines not on this page · raw message
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
A couple of comments below.
Quoted 24 lines · Terrence Xu
GVT-g (Intel® Graphics Virtualization Technology) is a full GPU virtualization solution with mediated pass-through support.
This tool is for create basic Linux guest based on KVMGT with VFIO framework, it including create vgpu, create guest, check IP address, destroy guest, remove vgpu,check dmesg log, etc functions.
v2: Treat this case as a free-standing tool, with detect & skip when it's not running on GVT-g capable platform or running without the required tools.
Signed-off-by Terrence Xu <[email protected]>Signed-off-by Benyu Xu <[email protected]>--- tools/Makefile.sources | 1 + tools/intel_gvtg_test.c | 355 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 356 insertions(+) create mode 100644 tools/intel_gvtg_test.ctools/Makefile.sources +0
-0
tools/Makefile.sources tools_prog_lists = \ · line 34
Quoted 5 lines
tools/Makefile.sources +1
-0@@ -30,6 +30,7 @@ tools_prog_lists = \ intel_stepping \ intel_watermark \ intel_gem_info \ + intel_gvtg_test \ $(NULL)
Check the indentation of that line.
Please add intel_gvtg_test to tools/.gitignore.
Quoted 75 lines
tools/Makefile.sources +0
-0dist_bin_SCRIPTS = intel_gpu_abrttools/intel_gvtg_test.c new file +67
-0@@ -0,0 +1,355 @@ +/* +* Copyright 2016 Intel Corporation +* Terrence Xu <[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +* IN THE SOFTWARE. +*/ + +/* +* This program is intended for testing of validate GVT-g virtual machine +* creation of allow for testing of KVMGT / XenGT. +* +* TODO: +* Enable more GVT-g related test cases. +*/ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "igt.h" +#include <errno.h> +#include <getopt.h> +#include <math.h> +#include <stdint.h> +#include <stdbool.h> +#include <strings.h> +#include <unistd.h> +#include <termios.h> +#include <sys/poll.h> +#include <sys/time.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <string.h> +#include <stdlib.h> +#include <signal.h> +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include <unistd.h> +#include <pwd.h> +#include <limits.h> + +#define RANDOM (x) (rand() % x) + +static uint32_t devid; + +static unsigned char mac_addr[17 ] = {'0' ,'0' ,':' ,'0' ,'0' ,':' , +'0' ,'0' ,':' ,'0' ,'0' ,':' ,'0' ,'0' ,':' ,'0' ,'0' }; +static char uuid[40 ]; +static char guest_ip[32 ]; +
tools/intel_gvtg_test.c line 77
Quoted 10 lines
tools/intel_gvtg_test.c new file +10
-0+static char qemu_path[PATH_MAX ] = {0 }; +static char hda_path[PATH_MAX ] = {0 }; +static char bios_path[PATH_MAX ] = {0 }; + +static int super_system (const char *cmd,char *retmsg,int msg_len) +{ +FILE *fp; +int res =-1 ; +if (cmd ==NULL || retmsg ==NULL || msg_len <0 ) { +igt_info ("Error: %s system paramer invalid!\n" , __func__);
paramer -> parameter
tools/intel_gvtg_test.c line 89
Quoted 12 lines
tools/intel_gvtg_test.c new file +12
-0+return 1 ; + } + fp =popen (cmd,"r" ); +if (fp ==NULL ) { +perror ("popen" ); +igt_info ("Error: %s popen error: %s\n" , __func__,strerror (errno)); +return 2 ; + }else { +memset (retmsg,0 , msg_len); +while (fgets (retmsg, msg_len, fp)) { + ; + };
Remove that semicolon after while's body's closing brace.
Quoted 9 lines
tools/intel_gvtg_test.c new file +9
-0+ res =pclose (fp); +if (res ==-1 ) { +igt_info ("Error:%s close popen file pointer fp error!\n" , __func__); +return 3 ; + } + retmsg[strlen (retmsg) -1 ] ='\0' ; +return 0 ; + } +}
tools/intel_gvtg_test.c line 108
Quoted 10 lines
tools/intel_gvtg_test.c new file +10
-0+ +static int check_platform (void ) +{ + devid =intel_get_pci_device ()->device_id; +if (IS_BROADWELL (devid) || (IS_SKYLAKE (devid))) { +return 0 ; + }else { +return 1 ; + } +}
This is not future-proof. And it doesn't really tell whether the running kernel has GVT-g support enabled. Is it possible to detect GVT-g support here?
Quoted 35 lines
tools/intel_gvtg_test.c new file +35
-0+ +static int check_tools (void ) +{ +if (system ("which uuidgen" ) !=0 ) { +return 1 ; + }else if (system ("which arp-scan" ) !=0 ) { +return 2 ; + } +return 0 ; +} + +static void create_guest (void ) +{ +char create_qcow_cmd[PATH_MAX ] = {0 }; +char create_vgpu_cmd[PATH_MAX ] = {0 }; +char create_instance_cmd[PATH_MAX ] = {0 }; + +sprintf (create_qcow_cmd,"qemu-img create -b %s -f qcow2 %s.qcow2" , + hda_path, hda_path); +sprintf (create_vgpu_cmd,"echo \"%s\" > /sys/bus/pci/devices/0000:00:02.0/" +"mdev_supported_types/i915-GVTg_V4_1/create" , uuid); +sprintf (create_instance_cmd,"%s -m 2048 -smp 2 -M pc -name gvtg_guest" +" -hda %s.qcow2 -bios %s -enable-kvm --net nic,macaddr=%s -net" +" tap,script=/etc/qemu-ifup -vga none -device isa-vga -k en-us" +" -serial stdio -vnc :1 -machine kernel_irqchip=on -global" +" PIIX4_PM.disable_s3=1 -global PIIX4_PM.disable_s4=1 -cpu host" +" -usb -usbdevice tablet -device vfio-pci,sysfsdev=" +"/sys/bus/pci/devices/0000:00:02.0/%s &" , + qemu_path, hda_path, bios_path, mac_addr, uuid); +igt_assert_eq (system (create_qcow_cmd),0 ); +igt_assert_eq (system (create_vgpu_cmd),0 ); +igt_assert_eq (system (create_instance_cmd),0 ); +} + +static void destroy_all_guest (void )
tools/intel_gvtg_test.c line 153
Quoted 10 lines
tools/intel_gvtg_test.c new file +10
-0+{ +system ("pkill qemu" ); +} + +static void remove_vgpu (void ) +{ +char cmd[128 ] = {0 }; +sprintf (cmd,"echo 1 > /sys/bus/pci/devices/0000:00:02.0/%s/remove" , uuid); +igt_assert_eq (system (cmd),0 ); +}
Doesn't this echo need root?
Quoted 23 lines
tools/intel_gvtg_test.c new file +23
-0+ +static void gen_mac_addr (void ) +{ +unsigned char mac_enum[16 ] = {'0' ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' , +'7' ,'8' ,'9' ,'A' ,'B' ,'C' ,'D' ,'E' ,'F' }; +unsigned short i, n =2 ; +srand (getpid ()); +for (i =2 , n =2 ; i <15 ; i++, n++) { +if (mac_addr[n] !=':' ) { + mac_addr[n] = mac_enum[RANDOM (16 )]; + } + } +} + +static void gen_uuid (void ) +{ +igt_assert_eq (super_system ("uuidgen" , uuid,sizeof (uuid)),0 ); +} + +static char *fetch_ip_by_mac (unsigned char *mac) +{ +char cmd[1024 ] = {0 }; + sprintf(cmd, "arp-scan -l -I $(ip addr show|grep inet|grep global|"
tools/intel_gvtg_test.c line 186
Quoted 10 lines
tools/intel_gvtg_test.c new file +10
-0+ "awk '{print $NF;}')|grep -i %s|awk '{print $1}'", mac); +igt_assert_eq (super_system (cmd, guest_ip,sizeof (guest_ip)),0 ); +return guest_ip; +} + +static int check_guest_ip (void ) +{ +int timeout =0 ; +while (timeout <=12 ) { +igt_info ("Try to connnect guest,the %d time.\n" , timeout);
Maybe: "Trying to connect to guest, attempt %d.\n"
Quoted 43 lines
tools/intel_gvtg_test.c new file +43
-0+if (timeout ==12 ) { +igt_info ("Cannot connect to guest.\n" ); +return 1 ; +break ; + } + +fetch_ip_by_mac (mac_addr); + +if (guest_ip[0 ] !='\0' ) { +igt_info ("Fetched guest ip address: %s.\n" , guest_ip); +break ; + } + timeout++; +sleep (5 ); + } +return 0 ; +} + +static void clear_dmesg (void ) +{ +igt_assert_eq (system ("dmesg -c" ),0 ); +} + +static int check_dmesg (void ) +{ +char errorlog[PATH_MAX ] = {0 }; + +igt_assert_eq (super_system ("dmesg|grep -E \"GPU HANG|gfx reset|BUG\"" , + errorlog,sizeof (errorlog)),0 ); + +if (errorlog[0 ] =='\0' ) { +return 0 ; + }else { +return 1 ; + } +} + +static const char optstr[] ="h" ; + +static void print_help (void ) +{ +igt_info ("\n [options]\n" + "-h, --help display usage\n"
tools/intel_gvtg_test.c line 239
Quoted 10 lines
tools/intel_gvtg_test.c new file +10
-0+"-q, --qemu the qemu path\n" +"-a, --hda the hda raw image / qcow path\n" +"-b, --bios the seabios path\n\n" + ); +} + +static void arg_mismatch (void ) +{ +igt_info (" argument mismatch!\n" ); +}
I don't see anything below in main() that tells the user which argument wasn't recognized.
Quoted 13 lines
tools/intel_gvtg_test.c new file +13
-0+ +int main (int argc,char **argv) +{ +int opt =-1 ; +const char *optstring ="hq:a:b:" ; +static struct option long_options[] = { + {"help" ,0 ,NULL ,'h' }, + {"qemu" ,1 ,NULL ,'q' }, + {"hda" ,1 ,NULL ,'a' }, + {"bios" ,1 ,NULL ,'b' }, + {0 ,0 ,0 ,0 } + }; +
tools/intel_gvtg_test.c line 262
Quoted 10 lines
tools/intel_gvtg_test.c new file +10
-0+int ret =0 ; +int flag_cnt =0 ; +int h_flag =0 ; +int q_flag =0 ; +int a_flag =0 ; +int b_flag =0 ; + +if (check_platform () ==1 ) { +igt_skip ("GVT-g technology only support Intel Broadwell and Skylake \ +platform.\n" );
This will print an awful looking line with loads of spaces, but the comment above on check_platform() applies here anyway.
--
Petri Latvala
Quoted 96 lines
tools/intel_gvtg_test.c new file +93
-0+ } +if (check_tools () ==1 ) { +igt_skip ("Please install the \"uuid-runtime\" tool.\n" ); + }else if (check_tools () ==2 ) { +igt_skip ("Please install the \"arp-scan\" tool.\n" ); + } + +if (argc ==1 ) { +print_help (); +return 0 ; + } + +while ((opt =getopt_long (argc, argv, optstring, long_options,NULL )) + !=-1 ) { +switch (opt) { +case 'h' : + h_flag =1 ; +break ; +case 'q' : +strcpy (qemu_path, optarg); + q_flag =1 ; +break ; +case 'a' : +strcpy (hda_path, optarg); + a_flag =1 ; +break ; +case 'b' : +strcpy (bios_path, optarg); + b_flag =1 ; +break ; +case ':' : + ret =-1 ; +break ; +case '?' : + ret =-1 ; +break ; + } + +if (ret) { +break ; + } + }; + +if (ret !=0 ) { +arg_mismatch (); +return ret; + } + + flag_cnt = h_flag + q_flag + a_flag + b_flag; + +if (flag_cnt ==1 ) { +if (h_flag ==1 ) { +print_help (); +return 0 ; + }else { +arg_mismatch (); +return -1 ; + } + }else if (flag_cnt ==3 ) { +if (q_flag ==1 && a_flag ==1 && b_flag ==1 ) { +igt_info ("\nqemu_path: %s\n hda_path: %s\n bios_path: %s\n" , + qemu_path, hda_path, bios_path); + }else { +arg_mismatch (); +return -1 ; + } + }else { +arg_mismatch (); +return -1 ; + } + +destroy_all_guest (); +clear_dmesg (); + +gen_mac_addr (); +gen_uuid (); +create_guest (); + +if (check_guest_ip ()) { + ret =1 ; + } + +destroy_all_guest (); +sleep (5 ); +remove_vgpu (); + +if (check_dmesg () >0 ) { + ret =1 ; + } + +igt_assert_eq (ret,0 ); +igt_exit (); +}Signature · 1 line
1.9.1
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
It is OK for me for all your comments, thanks! Just one question need to confirm with you inline.
Quoted 230 lines
A couple of comments below.
Quoted 25 lines · Terrence Xu
GVT-g (Intel(r) Graphics Virtualization Technology) is a full GPU virtualization solution with mediated pass-through support.
This tool is for create basic Linux guest based on KVMGT with VFIO framework, it including create vgpu, create guest, check IP address, destroy guest, remove vgpu,check dmesg log, etc functions.
v2: Treat this case as a free-standing tool, with detect & skip when it's not running on GVT-g capable platform or running without the required tools.
Signed-off-by Terrence Xu <[email protected]>Signed-off-by Benyu Xu <[email protected]>--- tools/Makefile.sources | 1 + tools/intel_gvtg_test.c | 355 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 356 insertions(+) create mode 100644 tools/intel_gvtg_test.ctools/Makefile.sources index renamed from tools/Makefile.sources +0
-0e2451ea..05ef0b7 100644
tools/Makefile.sources tools_prog_lists = \ · line 34
Quoted 5 lines
tools/Makefile.sources +1
-0@@ -30,6 +30,7 @@ tools_prog_lists = \ intel_stepping \ intel_watermark \ intel_gem_info \ + intel_gvtg_test \ $(NULL)Check the indentation of that line.
Please add
intel_gvtg_testtotools/.gitignore.Quoted 18 lines
tools/Makefile.sources +0
-0dist_bin_SCRIPTS = intel_gpu_abrttools/intel_gvtg_test.c new renamed from tools/intel_gvtg_test.c +0
-0file mode 100644 index 0000000..4c89800
tools/intel_gvtg_test.c new file +11
-0@@ -0,0 +1,355 @@ +/* +* Copyright 2016 Intel Corporation +* Terrence Xu <[email protected]> +* +* Permission is hereby granted, free of charge, to any person +obtaining a +* copy of this software and associated documentation files (the +"Software"), +* to deal in the Software without restriction, including without +limitation +* the rights to use, copy, modify, merge, publish, distribute, tools/intel_gvtg_test.c line 21
Quoted 10 lines
tools/intel_gvtg_test.c new file +10
-0+sublicense, + * and/or sell copies of the Software, and to permit persons to whom +the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be +included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANYKIND,
tools/intel_gvtg_test.c line 25
Quoted 4 lines
tools/intel_gvtg_test.c new file +4
-0+EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY , + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NOEVENT
tools/intel_gvtg_test.c line 27
Quoted 2 lines
tools/intel_gvtg_test.c new file +2
-0+SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,DAMAGES OR
tools/intel_gvtg_test.c line 31
Quoted 4 lines
tools/intel_gvtg_test.c new file +4
-0+OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USEOR
Quoted 39 lines
tools/intel_gvtg_test.c new file +39
-0+OTHER DEALINGS +* IN THE SOFTWARE. +*/ + +/* +* This program is intended for testing of validate GVT-g virtual +machine +* creation of allow for testing of KVMGT / XenGT. +* +* TODO: +* Enable more GVT-g related test cases. +*/ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "igt.h" +#include <errno.h> +#include <getopt.h> +#include <math.h> +#include <stdint.h> +#include <stdbool.h> +#include <strings.h> +#include <unistd.h> +#include <termios.h> +#include <sys/poll.h> +#include <sys/time.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <string.h> +#include <stdlib.h> +#include <signal.h> +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include <unistd.h> +#include <pwd.h> +#include <limits.h> tools/intel_gvtg_test.c
Quoted 10 lines
tools/intel_gvtg_test.c new file +10
-0+ +#define RANDOM (x) (rand() % x) + +static uint32_t devid; + +static unsigned char mac_addr[17 ] = {'0' ,'0' ,':' ,'0' ,'0' ,':' , +'0' ,'0' ,':' ,'0' ,'0' ,':' ,'0' ,'0' ,':' ,'0' ,'0' };static +char uuid[40 ];static char guest_ip[32 ]; + +static char qemu_path[PATH_MAX] = {0}; static charhda_path[PATH_MAX]
tools/intel_gvtg_test.c line 77
Quoted 7 lines
tools/intel_gvtg_test.c new file +7
-0+= {0 };static char bios_path[PATH_MAX ] = {0 }; + +static int super_system (const char *cmd,char *retmsg,int msg_len) { +FILE *fp; +int res =-1 ; +if (cmd ==NULL || retmsg ==NULL || msg_len <0 ) { +igt_info ("Error: %s system paramer invalid!\n" , __func__);paramer -> parameter
tools/intel_gvtg_test.c line 89
Quoted 12 lines
tools/intel_gvtg_test.c new file +12
-0+return 1 ; + } + fp =popen (cmd,"r" ); +if (fp ==NULL ) { +perror ("popen" ); +igt_info ("Error: %s popen error: %s\n" , __func__,strerror (errno)); +return 2 ; + }else { +memset (retmsg,0 , msg_len); +while (fgets (retmsg, msg_len, fp)) { + ; + };Remove that semicolon after while's body's closing brace.
Quoted 9 lines
tools/intel_gvtg_test.c new file +9
-0+ res =pclose (fp); +if (res ==-1 ) { +igt_info ("Error:%s close popen file pointer fp error!\n" , __func__); +return 3 ; + } + retmsg[strlen (retmsg) -1 ] ='\0' ; +return 0 ; + } +}tools/intel_gvtg_test.c line 108
Quoted 10 lines
tools/intel_gvtg_test.c new file +10
-0+ +static int check_platform (void ) +{ + devid =intel_get_pci_device ()->device_id; +if (IS_BROADWELL (devid) || (IS_SKYLAKE (devid))) { +return 0 ; + }else { +return 1 ; + } +}This is not future-proof. And it doesn't really tell whether the running kernel has GVT-g support enabled. Is it possible to detect GVT-g support here?
Quoted 10 lines
tools/intel_gvtg_test.c new file +10
-0+ +static int check_tools (void ) +{ +if (system ("which uuidgen" ) !=0 ) { +return 1 ; + }else if (system ("which arp-scan" ) !=0 ) { +return 2 ; + } +return 0 ; +}tools/intel_gvtg_test.c
Quoted 10 lines
tools/intel_gvtg_test.c new file +10
-0+ +static void create_guest (void ) +{ +char create_qcow_cmd[PATH_MAX ] = {0 }; +char create_vgpu_cmd[PATH_MAX ] = {0 }; +char create_instance_cmd[PATH_MAX ] = {0 }; + +sprintf (create_qcow_cmd,"qemu-img create -b %s -f qcow2 %s.qcow2" , + hda_path, hda_path); + sprintf(create_vgpu_cmd, "echo \"%s\" >/sys/bus/pci/devices/0000:00:02.0/"
tools/intel_gvtg_test.c line 140
Quoted 2 lines
tools/intel_gvtg_test.c new file +2
-0+ "mdev_supported_types/i915-GVTg_V4_1/create", uuid); + sprintf(create_instance_cmd, "%s -m 2048 -smp 2 -M pc -name
gvtg_guest"Quoted 10 lines
tools/intel_gvtg_test.c new file +10
-0+" -hda %s.qcow2 -bios %s -enable-kvm --net nic,macaddr=%s -net" +" tap,script=/etc/qemu-ifup -vga none -device isa-vga -k en-us" +" -serial stdio -vnc :1 -machine kernel_irqchip=on -global" +" PIIX4_PM.disable_s3=1 -global PIIX4_PM.disable_s4=1 -cpu host" +" -usb -usbdevice tablet -device vfio-pci,sysfsdev=" +"/sys/bus/pci/devices/0000:00:02.0/%s &" , + qemu_path, hda_path, bios_path, mac_addr, uuid); +igt_assert_eq (system (create_qcow_cmd),0 ); +igt_assert_eq (system (create_vgpu_cmd),0 ); +igt_assert_eq (system (create_instance_cmd),0 ); }tools/intel_gvtg_test.c
Quoted 10 lines
tools/intel_gvtg_test.c new file +10
-0+ +static void destroy_all_guest (void ) +{ +system ("pkill qemu" ); +} + +static void remove_vgpu (void ) +{ +char cmd[128 ] = {0 }; + sprintf(cmd, "echo 1 >/sys/bus/pci/devices/0000:00:02.0/%s/remove", uuid);
Quoted 4 lines
tools/intel_gvtg_test.c line 162
Quoted 2 lines
tools/intel_gvtg_test.c new file +2
-0+igt_assert_eq (system (cmd),0 ); +}Doesn't this echo need root?
[Xu, Terrence] Yes the root is needed for all our "echo" related commands, can I suppose the case is running under root privilege? Or need to return "skip" when it is not under root privilege?
Quoted 224 lines
Quoted 22 lines
tools/intel_gvtg_test.c new file +21
-0+ +static void gen_mac_addr (void ) +{ +unsigned char mac_enum[16 ] = {'0' ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' , +'7' ,'8' ,'9' ,'A' ,'B' ,'C' ,'D' ,'E' ,'F' }; +unsigned short i, n =2 ; +srand (getpid ()); +for (i =2 , n =2 ; i <15 ; i++, n++) { +if (mac_addr[n] !=':' ) { + mac_addr[n] = mac_enum[RANDOM (16 )]; + } + } +} + +static void gen_uuid (void ) +{ +igt_assert_eq (super_system ("uuidgen" , uuid,sizeof (uuid)),0 ); } + +static char *fetch_ip_by_mac (unsigned char *mac) { +char cmd[1024 ] = {0 }; + sprintf(cmd, "arp-scan -l -I $(ip addr show|grep inet|grep global|"tools/intel_gvtg_test.c line 186
Quoted 10 lines
tools/intel_gvtg_test.c new file +10
-0+ "awk '{print $NF;}')|grep -i %s|awk '{print $1}'", mac); +igt_assert_eq (super_system (cmd, guest_ip,sizeof (guest_ip)),0 ); +return guest_ip; +} + +static int check_guest_ip (void ) +{ +int timeout =0 ; +while (timeout <=12 ) { +igt_info ("Try to connnect guest,the %d time.\n" , timeout);Maybe: "Trying to connect to guest, attempt %d.\n"
Quoted 17 lines
tools/intel_gvtg_test.c new file +17
-0+if (timeout ==12 ) { +igt_info ("Cannot connect to guest.\n" ); +return 1 ; +break ; + } + +fetch_ip_by_mac (mac_addr); + +if (guest_ip[0 ] !='\0' ) { +igt_info ("Fetched guest ip address: %s.\n" , guest_ip); +break ; + } + timeout++; +sleep (5 ); + } +return 0 ; +}tools/intel_gvtg_test.c
Quoted 10 lines
tools/intel_gvtg_test.c new file +10
-0+ +static void clear_dmesg (void ) +{ +igt_assert_eq (system ("dmesg -c" ),0 ); } + +static int check_dmesg (void ) +{ +char errorlog[PATH_MAX ] = {0 }; + + igt_assert_eq(super_system("dmesg|grep -E \"GPU HANG|gfxreset|BUG\"",
Quoted 14 lines
tools/intel_gvtg_test.c new file +14
-0+ errorlog, sizeof(errorlog)), 0); + +if (errorlog[0 ] =='\0' ) { +return 0 ; + }else { +return 1 ; + } +} + +static const char optstr[] ="h" ; + +static void print_help (void ) +{ + igt_info("\n [options]\n"tools/intel_gvtg_test.c
Quoted 10 lines
tools/intel_gvtg_test.c new file +10
-0+"-h, --help display usage\n" +"-q, --qemu the qemu path\n" +"-a, --hda the hda raw image / qcow path\n" +"-b, --bios the seabios path\n\n" + ); +} + +static void arg_mismatch (void ) +{ +igt_info (" argument mismatch!\n" ); }I don't see anything below in
main()that tells the user which argument wasn't recognized.Quoted 12 lines
tools/intel_gvtg_test.c new file +12
-0+ +int main (int argc,char **argv) +{ +int opt =-1 ; +const char *optstring ="hq:a:b:" ; +static struct option long_options[] = { + {"help" ,0 ,NULL ,'h' }, + {"qemu" ,1 ,NULL ,'q' }, + {"hda" ,1 ,NULL ,'a' }, + {"bios" ,1 ,NULL ,'b' }, + {0 ,0 ,0 ,0 } + };tools/intel_gvtg_test.c
Quoted 10 lines
tools/intel_gvtg_test.c new file +10
-0+ +int ret =0 ; +int flag_cnt =0 ; +int h_flag =0 ; +int q_flag =0 ; +int a_flag =0 ; +int b_flag =0 ; + +if (check_platform () ==1 ) { + igt_skip("GVT-g technology only support Intel Broadwell and Skylake\
tools/intel_gvtg_test.c line 262
Quoted 1 line
tools/intel_gvtg_test.c new file +1
-0+ platform.\n");This will print an awful looking line with loads of spaces, but the comment above on
check_platform()applies here anyway.--
Petri LatvalaQuoted 88 lines
tools/intel_gvtg_test.c new file +88
-0+ } +if (check_tools () ==1 ) { +igt_skip ("Please install the \"uuid-runtime\" tool.\n" ); + }else if (check_tools () ==2 ) { +igt_skip ("Please install the \"arp-scan\" tool.\n" ); + } + +if (argc ==1 ) { +print_help (); +return 0 ; + } + +while ((opt =getopt_long (argc, argv, optstring, long_options,NULL )) + !=-1 ) { +switch (opt) { +case 'h' : + h_flag =1 ; +break ; +case 'q' : +strcpy (qemu_path, optarg); + q_flag =1 ; +break ; +case 'a' : +strcpy (hda_path, optarg); + a_flag =1 ; +break ; +case 'b' : +strcpy (bios_path, optarg); + b_flag =1 ; +break ; +case ':' : + ret =-1 ; +break ; +case '?' : + ret =-1 ; +break ; + } + +if (ret) { +break ; + } + }; + +if (ret !=0 ) { +arg_mismatch (); +return ret; + } + + flag_cnt = h_flag + q_flag + a_flag + b_flag; + +if (flag_cnt ==1 ) { +if (h_flag ==1 ) { +print_help (); +return 0 ; + }else { +arg_mismatch (); +return -1 ; + } + }else if (flag_cnt ==3 ) { +if (q_flag ==1 && a_flag ==1 && b_flag ==1 ) { +igt_info ("\nqemu_path: %s\n hda_path: %s\n bios_path: %s\n" , + qemu_path, hda_path, bios_path); + }else { +arg_mismatch (); +return -1 ; + } + }else { +arg_mismatch (); +return -1 ; + } + +destroy_all_guest (); +clear_dmesg (); + +gen_mac_addr (); +gen_uuid (); +create_guest (); + +if (check_guest_ip ()) { + ret =1 ; + } + +destroy_all_guest (); +sleep (5 ); +remove_vgpu (); + +if (check_dmesg () >0 ) { + ret =1 ;
Quoted 8 lines
Quoted 8 lines
tools/intel_gvtg_test.c new file +5
-1+ } + +igt_assert_eq (ret,0 ); +igt_exit (); +} --1.9.1
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 2 lines · Terrence
[Xu, Terrence] Yes the root is needed for all our "echo" related commands, can I suppose the case is running under root privilege? Or need to return "skip" when it is not under root privilege?
Right, seems I was a bit confused there and there are other cases where root rights are required.
Assuming root privileges is fine, especially if you're nice and warn the user if proper rights are not active. Can the tool be used as a normal user at all?
Signature · 6 lines
Petri Latvala _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 7 lines · Terrence
Quoted 1 line
[Xu, Terrence] Yes the root is needed for all our "echo" related commands,
can I suppose the case is running under root privilege? Or need to return "skip" when it is not under root privilege?
Quoted 1 line
Quoted 5 lines
Right, seems I was a bit confused there and there are other cases where root rights are required.
Assuming root privileges is fine, especially if you're nice and warn the user if proper rights are not active. Can the tool be used as a normal user at all?
[Xu, Terrence] It cannot be used as a normal user, since it need to call the sysfs, so I will choose to warn the user if proper rights are not active. :)
Quoted 8 lines
--
Petri Latvala_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx