/*-
* BSD LICENSE
*
- * Copyright(c) 2010-2012 Intel Corporation. All rights reserved.
+ * Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
* All rights reserved.
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
* are met:
*
- * * Redistributions of source code must retain the above copyright
+ * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
* distribution.
- * * Neither the name of Intel Corporation nor the names of its
- * contributors may be used to endorse or promote products derived
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
*/
#include <stdio.h>
static int
test_misc_flags(void)
{
+ FILE * hugedir_handle = NULL;
+ char line[PATH_MAX] = {0};
+ char hugepath[PATH_MAX] = {0};
char prefix[PATH_MAX], tmp[PATH_MAX];
+ unsigned i, isempty = 1;
+
if (get_current_prefix(tmp, sizeof(tmp)) == NULL) {
printf("Error - unable to get current prefix!\n");
return -1;
}
rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
+ /*
+ * get first valid hugepage path
+ */
+
+ /* get hugetlbfs mountpoints from /proc/mounts */
+ hugedir_handle = fopen("/proc/mounts", "r");
+
+ if (hugedir_handle == NULL) {
+ printf("Error opening /proc/mounts!\n");
+ return -1;
+ }
+
+ /* read /proc/mounts */
+ while (fgets(line, sizeof(line), hugedir_handle) != NULL) {
+
+ /* find first valid hugepath */
+ if (get_hugepage_path(line, sizeof(line), hugepath, sizeof(hugepath)))
+ break;
+ }
+
+ fclose(hugedir_handle);
+
+ /* check if path is not empty */
+ for (i = 0; i < sizeof(hugepath); i++)
+ if (hugepath[i] != '\0')
+ isempty = 0;
+
+ if (isempty) {
+ printf("No mounted hugepage dir found!\n");
+ return -1;
+ }
+
+
/* check that some general flags don't prevent things from working.
* All cases, apart from the first, app should run.
* No futher testing of output done.
const char *argv1[] = {prgname, prefix, mp_flag, "-c", "1", "--no-pci"};
/* With -v */
const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-v"};
+ /* With valid --syslog */
+ const char *argv3[] = {prgname, prefix, mp_flag, "-c", "1",
+ "--syslog", "syslog"};
+ /* With empty --syslog (should fail) */
+ const char *argv4[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog"};
+ /* With invalid --syslog */
+ const char *argv5[] = {prgname, prefix, mp_flag, "-c", "1", "--syslog", "error"};
+ /* With no-sh-conf */
+ const char *argv6[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
+ "--no-shconf", "--file-prefix=noshconf" };
+ /* With --huge-dir */
+ const char *argv7[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
+ "--file-prefix=hugedir", "--huge-dir", hugepath};
+ /* With empty --huge-dir (should fail) */
+ const char *argv8[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
+ "--file-prefix=hugedir", "--huge-dir"};
+ /* With invalid --huge-dir */
+ const char *argv9[] = {prgname, "-c", "1", "-n", "2", "-m", "2",
+ "--file-prefix=hugedir", "--huge-dir", "invalid"};
+ /* Secondary process with invalid --huge-dir (should run as flag has no
+ * effect on secondary processes) */
+ const char *argv10[] = {prgname, prefix, mp_flag, "-c", "1", "--huge-dir", "invalid"};
+
if (launch_proc(argv0) == 0) {
printf("Error - process ran ok with invalid flag\n");
printf("Error - process did not run ok with -v flag\n");
return -1;
}
+ if (launch_proc(argv3) != 0) {
+ printf("Error - process did not run ok with --syslog flag\n");
+ return -1;
+ }
+ if (launch_proc(argv4) == 0) {
+ printf("Error - process run ok with empty --syslog flag\n");
+ return -1;
+ }
+ if (launch_proc(argv5) == 0) {
+ printf("Error - process run ok with invalid --syslog flag\n");
+ return -1;
+ }
+ if (launch_proc(argv6) != 0) {
+ printf("Error - process did not run ok with --no-shconf flag\n");
+ return -1;
+ }
+ if (launch_proc(argv7) != 0) {
+ printf("Error - process did not run ok with --huge-dir flag\n");
+ return -1;
+ }
+ if (launch_proc(argv8) == 0) {
+ printf("Error - process run ok with empty --huge-dir flag\n");
+ return -1;
+ }
+ if (launch_proc(argv9) == 0) {
+ printf("Error - process run ok with invalid --huge-dir flag\n");
+ return -1;
+ }
+ if (launch_proc(argv10) != 0) {
+ printf("Error - secondary process did not run ok with invalid --huge-dir flag\n");
+ return -1;
+ }
return 0;
}