static int mymain(void) { int ret = 0; struct testFileSanitizePathData data1; #if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R # define MTAB_PATH1 abs_srcdir "/virfiledata/mounts1.txt" # define MTAB_PATH2 abs_srcdir "/virfiledata/mounts2.txt" static const char *wantmounts1[] = { "/proc", "/proc/sys/fs/binfmt_misc", "/proc/sys/fs/binfmt_misc", }; static const char *wantmounts1rev[] = { "/proc/sys/fs/binfmt_misc", "/proc/sys/fs/binfmt_misc", "/proc" }; static const char *wantmounts2a[] = { "/etc/aliases" }; static const char *wantmounts2b[] = { "/etc/aliases.db" }; # define DO_TEST_MOUNT_SUBTREE(name, path, prefix, mounts, rev) \ do { \ struct testFileGetMountSubtreeData data = { \ path, prefix, mounts, ARRAY_CARDINALITY(mounts), rev \ }; \ if (virTestRun(name, testFileGetMountSubtree, &data) < 0) \ ret = -1; \ } while (0) DO_TEST_MOUNT_SUBTREE("/proc normal", MTAB_PATH1, "/proc", wantmounts1, false); DO_TEST_MOUNT_SUBTREE("/proc reverse", MTAB_PATH1, "/proc", wantmounts1rev, true); DO_TEST_MOUNT_SUBTREE("/etc/aliases", MTAB_PATH2, "/etc/aliases", wantmounts2a, false); DO_TEST_MOUNT_SUBTREE("/etc/aliases.db", MTAB_PATH2, "/etc/aliases.db", wantmounts2b, false); #endif /* ! defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R */ #define DO_TEST_SANITIZE_PATH(PATH, EXPECT) \ do { \ data1.path = PATH; \ data1.expect = EXPECT; \ if (virTestRun(virTestCounterNext(), testFileSanitizePath, \ &data1) < 0) \ ret = -1; \ } while (0) #define DO_TEST_SANITIZE_PATH_SAME(PATH) DO_TEST_SANITIZE_PATH(PATH, PATH) virTestCounterReset("testFileSanitizePath "); DO_TEST_SANITIZE_PATH("", ""); DO_TEST_SANITIZE_PATH("/", "/"); DO_TEST_SANITIZE_PATH("/path", "/path"); DO_TEST_SANITIZE_PATH("/path/to/blah", "/path/to/blah"); DO_TEST_SANITIZE_PATH("/path/", "/path"); DO_TEST_SANITIZE_PATH("///////", "/"); DO_TEST_SANITIZE_PATH("//", "//"); DO_TEST_SANITIZE_PATH(".", "."); DO_TEST_SANITIZE_PATH("../", ".."); DO_TEST_SANITIZE_PATH("../../", "../.."); DO_TEST_SANITIZE_PATH("//foo//bar", "//foo/bar"); DO_TEST_SANITIZE_PATH("/bar//foo", "/bar/foo"); DO_TEST_SANITIZE_PATH_SAME("gluster://bar.baz/foo/hoo"); DO_TEST_SANITIZE_PATH_SAME("gluster://bar.baz//fooo/hoo"); DO_TEST_SANITIZE_PATH_SAME("gluster://bar.baz//////fooo/hoo"); DO_TEST_SANITIZE_PATH_SAME("gluster://bar.baz/fooo//hoo"); DO_TEST_SANITIZE_PATH_SAME("gluster://bar.baz/fooo///////hoo"); return ret != 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
static int mymain(void) { int ret = 0; virQEMUDriver driver; struct testBackingXMLjsonXMLdata xmljsonxmldata; struct testQemuDiskXMLToJSONData diskxmljsondata; char *capslatest_x86_64 = NULL; virQEMUCapsPtr caps_x86_64 = NULL; if (qemuTestDriverInit(&driver) < 0) return EXIT_FAILURE; diskxmljsondata.driver = &driver; if (!(capslatest_x86_64 = testQemuGetLatestCapsForArch("x86_64", "xml"))) return EXIT_FAILURE; VIR_TEST_VERBOSE("\nlatest caps x86_64: %s\n", capslatest_x86_64); if (!(caps_x86_64 = qemuTestParseCapabilitiesArch(virArchFromString("x86_64"), capslatest_x86_64))) return EXIT_FAILURE; diskxmljsondata.qemuCaps = caps_x86_64; virTestCounterReset("qemu storage source xml->json->xml "); # define TEST_JSON_FORMAT(tpe, xmlstr) \ do { \ xmljsonxmldata.type = tpe; \ xmljsonxmldata.xml = xmlstr; \ if (virTestRun(virTestCounterNext(), testBackingXMLjsonXML, \ &xmljsonxmldata) < 0) \ ret = -1; \ } while (0) # define TEST_JSON_FORMAT_NET(xmlstr) \ TEST_JSON_FORMAT(VIR_STORAGE_TYPE_NETWORK, xmlstr) TEST_JSON_FORMAT(VIR_STORAGE_TYPE_FILE, "<source file='/path/to/file'/>\n"); /* type VIR_STORAGE_TYPE_BLOCK is not tested since it parses back to 'file' */ /* type VIR_STORAGE_TYPE_DIR it is a 'format' driver in qemu */ TEST_JSON_FORMAT_NET("<source protocol='http' name=''>\n" " <host name='example.com' port='80'/>\n" "</source>\n"); TEST_JSON_FORMAT_NET("<source protocol='http' name='file'>\n" " <host name='example.com' port='80'/>\n" "</source>\n"); TEST_JSON_FORMAT_NET("<source protocol='https' name='file'>\n" " <host name='example.com' port='432'/>\n" "</source>\n"); TEST_JSON_FORMAT_NET("<source protocol='gluster' name='vol/file'>\n" " <host name='example.com' port='24007'/>\n" "</source>\n"); TEST_JSON_FORMAT_NET("<source protocol='gluster' name='testvol/img.qcow2'>\n" " <host name='example.com' port='1234'/>\n" " <host transport='unix' socket='/path/socket'/>\n" " <host name='example.com' port='24007'/>\n" "</source>\n"); TEST_JSON_FORMAT_NET("<source protocol='nbd'>\n" " <host transport='unix' socket='/path/to/socket'/>\n" "</source>\n"); TEST_JSON_FORMAT_NET("<source protocol='nbd' name='blah'>\n" " <host name='example.org' port='6000'/>\n" "</source>\n"); TEST_JSON_FORMAT_NET("<source protocol='nbd'>\n" " <host name='example.org' port='6000'/>\n" "</source>\n"); TEST_JSON_FORMAT_NET("<source protocol='ssh' name='blah'>\n" " <host name='example.org' port='6000'/>\n" "</source>\n"); TEST_JSON_FORMAT_NET("<source protocol='rbd' name='libvirt/test'>\n" " <host name='example.com' port='1234'/>\n" " <host name='example2.com'/>\n" " <snapshot name='snapshotname'/>\n" " <config file='/path/to/conf'/>\n" "</source>\n"); TEST_JSON_FORMAT_NET("<source protocol='iscsi' name='iqn.2016-12.com.virttest:emulated-iscsi-noauth.target/0'>\n" " <host name='test.org' port='3260'/>\n" "</source>\n"); TEST_JSON_FORMAT_NET("<source protocol='iscsi' name='iqn.2016-12.com.virttest:emulated-iscsi-noauth.target/6'>\n" " <host name='test.org' port='1234'/>\n" "</source>\n"); TEST_JSON_FORMAT_NET("<source protocol='sheepdog' name='test'>\n" " <host name='example.com' port='321'/>\n" "</source>\n"); TEST_JSON_FORMAT_NET("<source protocol='vxhs' name='c6718f6b-0401-441d-a8c3-1f0064d75ee0'>\n" " <host name='example.com' port='9999'/>\n" "</source>\n"); # define TEST_DISK_TO_JSON_FULL(nme, fl) \ do { \ diskxmljsondata.name = nme; \ diskxmljsondata.props = NULL; \ diskxmljsondata.nprops = 0; \ diskxmljsondata.fail = fl; \ if (virTestRun("disk xml to props " nme, testQemuDiskXMLToProps, \ &diskxmljsondata) < 0) \ ret = -1; \ if (virTestRun("disk xml to props validate schema " nme, \ testQemuDiskXMLToPropsValidateSchema, &diskxmljsondata) < 0) \ ret = -1; \ if (virTestRun("disk xml to props validate file " nme, \ testQemuDiskXMLToPropsValidateFile, &diskxmljsondata) < 0) \ ret = -1; \ testQemuDiskXMLToPropsClear(&diskxmljsondata); \ } while (0) # define TEST_DISK_TO_JSON(nme) TEST_DISK_TO_JSON_FULL(nme, false) if (!(diskxmljsondata.schema = testQEMUSchemaLoad())) { ret = -1; goto cleanup; } if (virQEMUQAPISchemaPathGet("blockdev-add/arg-type", diskxmljsondata.schema, &diskxmljsondata.schemaroot) < 0 || !diskxmljsondata.schemaroot) { VIR_TEST_VERBOSE("failed to find schema entry for blockdev-add\n"); ret = -1; goto cleanup; } TEST_DISK_TO_JSON_FULL("nodename-long-format", true); TEST_DISK_TO_JSON_FULL("nodename-long-protocol", true); TEST_DISK_TO_JSON("file-raw-noopts"); TEST_DISK_TO_JSON("file-bochs-noopts"); TEST_DISK_TO_JSON("file-cloop-noopts"); TEST_DISK_TO_JSON("file-dmg-noopts"); TEST_DISK_TO_JSON("file-ploop-noopts"); TEST_DISK_TO_JSON("file-vdi-noopts"); TEST_DISK_TO_JSON("file-vhd-noopts"); TEST_DISK_TO_JSON("file-vpc-noopts"); TEST_DISK_TO_JSON("file-backing_basic-noopts"); TEST_DISK_TO_JSON("dir-fat-readonly"); TEST_DISK_TO_JSON("dir-fat-floppy"); TEST_DISK_TO_JSON("file-raw-aio_native"); TEST_DISK_TO_JSON("file-backing_basic-aio_threads"); TEST_DISK_TO_JSON("file-raw-luks"); TEST_DISK_TO_JSON("file-qcow2-backing-chain-noopts"); TEST_DISK_TO_JSON("file-qcow2-backing-chain-unterminated"); TEST_DISK_TO_JSON("file-qcow2-backing-chain-encryption"); TEST_DISK_TO_JSON("network-qcow2-backing-chain-encryption_auth"); TEST_DISK_TO_JSON("file-backing_basic-unmap"); TEST_DISK_TO_JSON("file-backing_basic-unmap-detect"); TEST_DISK_TO_JSON("file-backing_basic-unmap-ignore"); TEST_DISK_TO_JSON("file-backing_basic-detect"); TEST_DISK_TO_JSON("file-backing_basic-cache-none"); TEST_DISK_TO_JSON("file-backing_basic-cache-writethrough"); TEST_DISK_TO_JSON("file-backing_basic-cache-writeback"); TEST_DISK_TO_JSON("file-backing_basic-cache-directsync"); TEST_DISK_TO_JSON("file-backing_basic-cache-unsafe"); TEST_DISK_TO_JSON("network-qcow2-backing-chain-cache-unsafe"); TEST_DISK_TO_JSON("dir-fat-cache"); TEST_DISK_TO_JSON("network-nbd-tls"); TEST_DISK_TO_JSON("block-raw-noopts"); TEST_DISK_TO_JSON("block-raw-reservations"); cleanup: virHashFree(diskxmljsondata.schema); qemuTestDriverFree(&driver); VIR_FREE(capslatest_x86_64); virObjectUnref(caps_x86_64); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; }