test/cfgfile: add realloc scenario
authorJacek Piasecki <jacekx.piasecki@intel.com>
Fri, 22 Sep 2017 09:44:50 +0000 (11:44 +0200)
committerThomas Monjalon <thomas@monjalon.net>
Sun, 8 Oct 2017 22:52:37 +0000 (00:52 +0200)
Load huge realloc_sections.ini file to check malloc/realloc
ability of cfgfile library.

Signed-off-by: Jacek Piasecki <jacekx.piasecki@intel.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
test/test/test_cfgfile.c
test/test/test_cfgfiles/etc/realloc_sections.ini [new file with mode: 0644]

index 4cc9b14..37435b3 100644 (file)
@@ -153,6 +153,43 @@ test_cfgfile_sample2(void)
        return 0;
 }
 
+static int
+test_cfgfile_realloc_sections(void)
+{
+       struct rte_cfgfile *cfgfile;
+       int ret;
+       const char *value;
+
+       cfgfile = rte_cfgfile_load(CFG_FILES_ETC "/realloc_sections.ini", 0);
+       TEST_ASSERT_NOT_NULL(cfgfile, "Failed to load config file");
+
+       ret = rte_cfgfile_num_sections(cfgfile, NULL, 0);
+       TEST_ASSERT(ret == 9, "Unexpected number of sections: %d", ret);
+
+       ret = rte_cfgfile_has_section(cfgfile, "section9");
+       TEST_ASSERT(ret, "section9 missing");
+
+       ret = rte_cfgfile_section_num_entries(cfgfile, "section3");
+       TEST_ASSERT(ret == 21,
+                       "section3 unexpected number of entries: %d", ret);
+
+       ret = rte_cfgfile_section_num_entries(cfgfile, "section9");
+       TEST_ASSERT(ret == 8, "section9 unexpected number of entries: %d", ret);
+
+       value = rte_cfgfile_get_entry(cfgfile, "section9", "key8");
+       TEST_ASSERT(strcmp("value8_section9", value) == 0,
+                   "key unexpected value: %s", value);
+
+       ret = rte_cfgfile_save(cfgfile, "/tmp/cfgfile_save.ini");
+       TEST_ASSERT_SUCCESS(ret, "Failed to save *.ini file");
+       remove("/tmp/cfgfile_save.ini");
+
+       ret = rte_cfgfile_close(cfgfile);
+       TEST_ASSERT_SUCCESS(ret, "Failed to close cfgfile");
+
+       return 0;
+}
+
 static int
 test_cfgfile_invalid_section_header(void)
 {
@@ -292,6 +329,9 @@ test_cfgfile(void)
        if (test_cfgfile_sample2())
                return -1;
 
+       if (test_cfgfile_realloc_sections())
+               return -1;
+
        if (test_cfgfile_invalid_section_header())
                return -1;
 
diff --git a/test/test/test_cfgfiles/etc/realloc_sections.ini b/test/test/test_cfgfiles/etc/realloc_sections.ini
new file mode 100644 (file)
index 0000000..e653e40
--- /dev/null
@@ -0,0 +1,128 @@
+[section1]
+key1=value1_section1
+key2=value2_section1
+key3=value3_section1
+key4=value4_section1
+key5=value5_section1
+key6=value6_section1
+key7=value7_section1
+key8=value8_section1
+key9=value9_section1
+key10=value10_section1
+key11=value11_section1
+key12=value12_section1
+key13=value13_section1
+key14=value14_section1
+key15=value15_section1
+key16=value16_section1
+key17=value17_section1
+key18=value18_section1
+key19=value19_section1
+key20=value20_section1
+key21=value21_section1
+
+[section2]
+key1=value1_section2
+key2=value2_section2
+key3=value3_section2
+key4=value4_section2
+key5=value5_section2
+key6=value6_section2
+key7=value7_section2
+key8=value8_section2
+key9=value9_section2
+key10=value10_section2
+key11=value11_section2
+key12=value12_section2
+key13=value13_section2
+key14=value14_section2
+key15=value15_section2
+key16=value16_section2
+key17=value17_section2
+key18=value18_section2
+key19=value19_section2
+key20=value20_section2
+key21=value21_section2
+
+[section3]
+key1=value1_section3
+key2=value2_section3
+key3=value3_section3
+key4=value4_section3
+key5=value5_section3
+key6=value6_section3
+key7=value7_section3
+key8=value8_section3
+key9=value9_section3
+key10=value10_section3
+key11=value11_section3
+key12=value12_section3
+key13=value13_section3
+key14=value14_section3
+key15=value15_section3
+key16=value16_section3
+key17=value17_section3
+key18=value18_section3
+key19=value19_section3
+key20=value20_section3
+key21=value21_section3
+
+[section4]
+key1=value1_section4
+key2=value2_section4
+key3=value3_section4
+key4=value4_section4
+key5=value5_section4
+key6=value6_section4
+key7=value7_section4
+key8=value8_section4
+
+[section5]
+key1=value1_section5
+key2=value2_section5
+key3=value3_section5
+key4=value4_section5
+key5=value5_section5
+key6=value6_section5
+key7=value7_section5
+key8=value8_section5
+
+[section6]
+key1=value1_section6
+key2=value2_section6
+key3=value3_section6
+key4=value4_section6
+key5=value5_section6
+key6=value6_section6
+key7=value7_section6
+key8=value8_section6
+
+[section7]
+key1=value1_section7
+key2=value2_section7
+key3=value3_section7
+key4=value4_section7
+key5=value5_section7
+key6=value6_section7
+key7=value7_section7
+key8=value8_section7
+
+[section8]
+key1=value1_section8
+key2=value2_section8
+key3=value3_section8
+key4=value4_section8
+key5=value5_section8
+key6=value6_section8
+key7=value7_section8
+key8=value8_section8
+
+[section9]
+key1=value1_section9
+key2=value2_section9
+key3=value3_section9
+key4=value4_section9
+key5=value5_section9
+key6=value6_section9
+key7=value7_section9
+key8=value8_section9