diff options
author | Dhaval Giani <dhaval@linux.vnet.ibm.com> | 2009-01-06 08:47:57 +0000 |
---|---|---|
committer | Dhaval Giani <dhaval@linux.vnet.ibm.com> | 2009-01-06 08:47:57 +0000 |
commit | 16dec13a18c4fae5c7cf6441f75bfa354151f1b4 (patch) | |
tree | 0edf6eae6b09f1d2a5d60d69ad8c9e1337077e22 /tests/libcgrouptest01.c | |
parent | 2b9ea8fe926382dfa7623547bd5ae8740493c618 (diff) | |
download | libcg-16dec13a18c4fae5c7cf6441f75bfa354151f1b4.tar.gz libcg-16dec13a18c4fae5c7cf6441f75bfa354151f1b4.tar.xz libcg-16dec13a18c4fae5c7cf6441f75bfa354151f1b4.zip |
libcgroup: Fix low hanging cleanups
Some of the cleanups possible are obvious.
1. Change usage of strcat to strncat
2. Change usage of tge following type
char *s = malloc();
strcpy(s, "somestring");
strcat(s, "someotherstring");
to something more easily understandble such as
asprintf(&s, "%s%s", somestring, someotherstring);
Changes for v2:
1. Fix some memory leaks discovered using valgrind
2. Fix Balbir's comments regarding codingstyle.
3. Move the controllers array memory leak fix into another patch
Changes from v1:
1. Correct the error handling of asprintf as pointed out by Dan Smith
TODO:
1. Figure out what is the correct value of n for cg_build_path_locked
valgrind output,
[root@gondor tests]# sh runlibcgrouptest.sh
Running first set of testcases
==============================
==5067== Memcheck, a memory error detector.
==5067== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==5067== Using LibVEX rev 1804, a library for dynamic binary translation.
==5067== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==5067== Using valgrind-3.3.0, a dynamic binary instrumentation framework.
==5067== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==5067== For more details, rerun with: -v
==5067==
C:DBG: fs_mounted as recieved from script=0
TEST 1:PASS : cgroup_init() Ret Value = 50001
TEST 2:PASS : cgroup_attach_task() Ret Value = 50014 Parameter nullcgroup
TEST 3:PASS : cgroup_new_cgroup() Ret Value = 0
TEST 4:PASS : cgroup_create_cgroup() Ret Value = 50014
TEST 5:PASS : cgroup_delete_cgroup() Ret Value = 50014
TEST 6:PASS : cgroup_create_cgroup() Ret Value = 50014
TEST 7:PASS : cgroup_delete_cgroup() Ret Value = 50014
TEST 8:PASS : cgroup_add_controller() Ret Value = 0
TEST 9:PASS : cgroup_add_controller() Ret Value = 0
TEST10:PASS : cgroup_add_controller() Ret Value = 0
==5067==
==5067== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 18 from 1)
==5067== malloc/free: in use at exit: 0 bytes in 0 blocks.
==5067== malloc/free: 18 allocs, 18 frees, 32,293 bytes allocated.
==5067== For counts of detected errors, rerun with: -v
==5067== All heap blocks were freed -- no leaks are possible.
Running second set of testcases
==============================
==5083== Memcheck, a memory error detector.
==5083== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==5083== Using LibVEX rev 1804, a library for dynamic binary translation.
==5083== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==5083== Using valgrind-3.3.0, a dynamic binary instrumentation framework.
==5083== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==5083== For more details, rerun with: -v
==5083==
C:DBG: fs_mounted as recieved from script=1
C:DBG: mountpoint1 as recieved from script=/dev/cgroup_controllers-1
sanity check pass. cgroup
TEST 1:PASS : cgroup_attach_task() Ret Value = 50014 Parameter nullcgroup
TEST 2:PASS : cgroup_init() Ret Value = 0
TEST 3:PASS : cgroup_attach_task() Ret Value = 0 Task found in group/s
TEST 4:PASS : cgroup_attach_task_pid() Ret Value = 50016
TEST 5:PASS : cgroup_new_cgroup() Ret Value = 0
TEST 6:PASS : cgroup_create_cgroup() Ret Value = 0 group found in filesystem
TEST 7:PASS : cgroup_attach_task() Ret Value = 0 Task found in group/s
==5083== Conditional jump or move depends on uninitialised value(s)
==5083== at 0x40070D8: strncat (mc_replace_strmem.c:214)
==5083== by 0x804BC92: main (libcgrouptest01.c:1271)
==5083== at 0x40070D8: strncat (mc_replace_strmem.c:214)
==5083== by 0x804BC92: main (libcgrouptest01.c:1271)
==5083==
==5083== Conditional jump or move depends on uninitialised value(s)
==5083== at 0x8049471: _ZL14group_modifiedPci (libcgrouptest01.c:1076)
==5083== by 0x804C583: main (libcgrouptest01.c:254)
==5083==
==5083== Conditional jump or move depends on uninitialised value(s)
==5083== at 0x8049479: _ZL14group_modifiedPci (libcgrouptest01.c:1076)
==5083== by 0x804C583: main (libcgrouptest01.c:254)
==5083==
==5083== Conditional jump or move depends on uninitialised value(s)
==5083== at 0x4007470: strncmp (mc_replace_strmem.c:314)
==5083== by 0x804949B: _ZL14group_modifiedPci (libcgrouptest01.c:1076)
==5083== by 0x804C583: main (libcgrouptest01.c:254)
==5083==
==5083== Conditional jump or move depends on uninitialised value(s)
==5083== at 0x4007475: strncmp (mc_replace_strmem.c:314)
==5083== by 0x804949B: _ZL14group_modifiedPci (libcgrouptest01.c:1076)
==5083== by 0x804C583: main (libcgrouptest01.c:254)
==5083==
==5083== Conditional jump or move depends on uninitialised value(s)
==5083== at 0x4007497: strncmp (mc_replace_strmem.c:314)
==5083== by 0x804949B: _ZL14group_modifiedPci (libcgrouptest01.c:1076)
==5083== by 0x804C583: main (libcgrouptest01.c:254)
==5083==
==5083== Conditional jump or move depends on uninitialised value(s)
==5083== at 0x40074A0: strncmp (mc_replace_strmem.c:314)
==5083== by 0x804949B: _ZL14group_modifiedPci (libcgrouptest01.c:1076)
==5083== by 0x804C583: main (libcgrouptest01.c:254)
TEST 8:FAIL : cgroup_modify_cgroup() Ret Value = 0 Parameter same cgroup
TEST 9:PASS : cgroup_new_cgroup() Ret Value = 0
TEST10:PASS : cgroup_modify_cgroup() Ret Value = 0
TEST11:PASS : cgroup_modify_cgroup() Ret Value = 50007
TEST12:PASS : cgroup_new_cgroup() Ret Value = 0
TEST13:PASS : cgroup_modify_cgroup() Ret Value = 0
TEST14:PASS : cgroup_get_cgroup() Ret Value = 50007 Parameter nullcgroup
TEST15:PASS : cgroup_get_cgroup() Ret Value = 50002 Parameter not created group
TEST16:PASS : cgroup_get_cgroup() Ret Value = 0
TEST 0:PASS : cgroup_new_cgroup() Ret Value = 0
TEST 0:PASS : cgroup_create_cgroup() Ret Value = 0 group found in filesystem
TEST17:FAIL : cgroup_get_cgroup() Ret Value = 50017
TEST16:PASS : cgroup_delete_cgroup() Ret Value = 0 Group deleted from filesystem
TEST17:PASS : cgroup_create_cgroup() Ret Value = 50007
TEST18:PASS : cgroup_delete_cgroup() Ret Value = 50007
TEST19:PASS : cgroup_compare_cgroup() Ret Value = 50011 Parameter nullcgroup
TEST20:PASS : cgroup_compare_cgroup() Ret Value = 0
TEST21:PASS : cgroup_compare_cgroup() Ret Value = 50017
==5083==
==5083== ERROR SUMMARY: 9 errors from 7 contexts (suppressed: 18 from 1)
==5083== malloc/free: in use at exit: 0 bytes in 0 blocks.
==5083== malloc/free: 279 allocs, 279 frees, 237,968 bytes allocated.
==5083== For counts of detected errors, rerun with: -v
==5083== All heap blocks were freed -- no leaks are possible.
Cleanup done
Running third set of testcases
==============================
==5134== Memcheck, a memory error detector.
==5134== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==5134== Using LibVEX rev 1804, a library for dynamic binary translation.
==5134== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==5134== Using valgrind-3.3.0, a dynamic binary instrumentation framework.
==5134== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==5134== For more details, rerun with: -v
==5134==
C:DBG: fs_mounted as recieved from script=2
C:DBG: mountpoint1 as recieved from script=/dev/cgroup_controllers-1
C:DBG: mountpoint2 as recieved from script=/dev/cgroup_controllers-2
sanity check pass. cgroup
TEST 1:PASS : cgroup_init() Ret Value = 0
TEST 2:PASS : cgroup_attach_task() Ret Value = 0 Task found in group/s
TEST 3:PASS : cgroup_new_cgroup() Ret Value = 0
TEST 4:PASS : cgroup_create_cgroup() Ret Value = 0 group found in filesystem
TEST 5:PASS : cgroup_new_cgroup() Ret Value = 0
TEST 6:PASS : cgroup_create_cgroup() Ret Value = 0 group found in filesystem
TEST 5:PASS : cgroup_new_cgroup() Ret Value = 0
TEST 6:PASS : cgroup_create_cgroup() Ret Value = 0 group found in filesystem
TEST 7:PASS : cgroup_create_cgroup() Ret Value = 0 group found in filesystem
TEST 8:PASS : cgroup_attach_task() Ret Value = 0 Task found in group/s
TEST 9:PASS : cgroup_attach_task() Ret Value = 0 Task found in group/s
TEST10:PASS : cgroup_new_cgroup() Ret Value = 0
TEST11:PASS : cgroup_attach_task() Ret Value = 50002 Parameter not created group
TEST12:PASS : cgroup_new_cgroup() Ret Value = 0
TEST13:PASS : cgroup_modify_cgroup() Ret Value = 0
TEST14:PASS : cgroup_new_cgroup() Ret Value = 0
TEST15:PASS : cgroup_modify_cgroup() Ret Value = 0
TEST16:PASS : cgroup_delete_cgroup() Ret Value = 0 Group deleted from filesystem
TEST17:PASS : cgroup_delete_cgroup() Ret Value = 0 Group deleted from filesystem
TEST18:PASS : cgroup_new_cgroup() Ret Value = 0
TEST19:PASS : cgroup_create_cgroup() Ret Value = 0 group found under both controllers
TEST20:PASS : cgroup_attach_task() Ret Value = 0 Task found in group/s
TEST21:PASS : cgroup_new_cgroup() Ret Value = 0
TEST22:PASS : cgroup_modify_cgroup() Ret Value = 0 group modified under both controllers
TEST23:PASS : cgroup_delete_cgroup() Ret Value = 0 Group deleted from filesystem
TEST 0:PASS : cgroup_new_cgroup() Ret Value = 0
TEST 0:PASS : cgroup_create_cgroup() Ret Value = 0 group found in filesystem
TEST24:FAIL : cgroup_get_cgroup() Ret Value = 50018
==5134==
==5134== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 18 from 1)
==5134== malloc/free: in use at exit: 66,044 bytes in 15 blocks.
==5134== malloc/free: 279 allocs, 264 frees, 232,094 bytes allocated.
==5134== For counts of detected errors, rerun with: -v
==5134== searching for pointers to 15 not-freed blocks.
==5134== checked 6,381,388 bytes.
==5134==
==5134== 66,044 (18,064 direct, 47,980 indirect) bytes in 4 blocks are definitely lost in loss record 1 of 3
==5134== at 0x4004BA2: calloc (vg_replace_malloc.c:397)
==5134== by 0x4030DAA: cgroup_new_cgroup (wrapper.c:28)
==5134== by 0x8049656: new_cgroup(char*, char*, char*, int, int) (libcgrouptest01.c:1132)
==5134== by 0x8049917: create_new_cgroup_ds(int, char const*, int, int) (libcgrouptest01.c:744)
==5134== by 0x804C190: main (libcgrouptest01.c:485)
==5134==
==5134==
==5134== 20,980 bytes in 5 blocks are indirectly lost in loss record 2 of 3
==5134== at 0x4004BA2: calloc (vg_replace_malloc.c:397)
==5134== by 0x4030C3C: cgroup_add_value_string (wrapper.c:122)
==5134== by 0x8048FDB: _ZL17add_control_valueP17cgroup_controllerPcS1_i (libcgrouptest01.c:1113)
==5134== by 0x80496C9: new_cgroup(char*, char*, char*, int, int) (libcgrouptest01.c:1147)
==5134== by 0x8049917: create_new_cgroup_ds(int, char const*, int, int) (libcgrouptest01.c:744)
==5134== by 0x804C190: main (libcgrouptest01.c:485)
==5134==
==5134==
==5134== 27,000 bytes in 6 blocks are indirectly lost in loss record 3 of 3
==5134== at 0x4004BA2: calloc (vg_replace_malloc.c:397)
==5134== by 0x4030F5B: cgroup_add_controller (wrapper.c:62)
==5134== by 0x80496AE: new_cgroup(char*, char*, char*, int, int) (libcgrouptest01.c:1144)
==5134== by 0x8049917: create_new_cgroup_ds(int, char const*, int, int) (libcgrouptest01.c:744)
==5134== by 0x804C190: main (libcgrouptest01.c:485)
==5134==
==5134== LEAK SUMMARY:
==5134== definitely lost: 18,064 bytes in 4 blocks.
==5134== indirectly lost: 47,980 bytes in 11 blocks.
==5134== possibly lost: 0 bytes in 0 blocks.
==5134== still reachable: 0 bytes in 0 blocks.
==5134== suppressed: 0 bytes in 0 blocks.
Cleanup done
[root@gondor tests]#
Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com>
git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@302 4f4bb910-9a46-0410-90c8-c897d4f1cd53
Diffstat (limited to 'tests/libcgrouptest01.c')
0 files changed, 0 insertions, 0 deletions