This test shows the amount of memory used by the system.
Note that this is dependent on the user-space that is loaded
when this program runs. Optimally, this program would be
run as the init program itself.
The program is optimized for size itself, to avoid conflating
its own execution with that of the system software.
The code is compiled statically, with no stdlibs. On my x86_64 system,
this results in a statically linked binary of less than 5K.
Signed-off-by: Tim Bird <redacted>
---
tools/testing/selftests/Makefile | 1 +
tools/testing/selftests/size/Makefile | 21 +++++++
tools/testing/selftests/size/get_size.c | 105 ++++++++++++++++++++++++++++++++
3 files changed, 127 insertions(+)
create mode 100644 tools/testing/selftests/size/Makefile
create mode 100644 tools/testing/selftests/size/get_size.c
@@ -0,0 +1,105 @@+/*+*Copyright2014Sony+*+*LicensedunderthetermsoftheGNUGPLLicenseversion2+*+*Selftestforruntimesystemsize+*+*PrintstheamountofRAMthatthecurrentlyrunningsystemisusing.+*+*Thisprogramtriestobeassmallaspossibleitself,to+*avoidperturbingthesystemmemoryutilizationwithits+*ownexecution.Italsoattemptstohaveasfewdependencies+*onkernelfeaturesaspossible.+*+*Itshouldbestaticallylinked,withstartuplibsavoided.+*Itusesnolibrarycalls,andonlythefollowing3syscalls:+*sysinfo(),write(),and_exit()+*+*Foroutput,itavoidsprintf(whichinsomeClibraries+*haslargeexternaldependencies)byimplementingitsown+*strlen(),numberoutputandprint()routines.+*/++#include<sys/sysinfo.h>+#include<unistd.h>++#define STDOUT_FILENO 1++my_strlen(constchar*s)+{+intlen=0;++while(*s++)+len++;+returnlen;+}++/*+*num_to_str-putdigitsfromnuminto*s,lefttoright+*dothisbydividingthenumberbypowersof10+*thetrickypartistoomitleadingzeros+*don'tprintzerosuntilwe'vestartedprintinganynumbersatall+*/+staticvoidnum_to_str(unsignedlongnum,char*s)+{+unsignedlonglongtemp,div;+intstarted;++temp=num;+div=1000000000000000000LL;+started=0;+while(div){+if(temp/div||started){+*s++=(unsignedchar)(temp/div+'0');+started=1;+}+temp-=(temp/div)*div;+div/=10;+}+*s=0;+}++print_num(unsignedlongnum)+{+charnum_buf[30];++num_to_str(num,num_buf);+write(STDOUT_FILENO,num_buf,my_strlen(num_buf));+}++print(char*s)+{+write(STDOUT_FILENO,s,my_strlen(s));+}++voidmain(intargc,char**argv)+{+intccode;+unsignedlongused;+structsysinfoinfo;+unsignedlonglongtemp;++print("Testing system size.\n");+print("1..1\n");++ccode=sysinfo(&info);+if(ccode<0){+print("not ok 1 get size runtime size\n");+print("# could not get sysinfo\n");+_exit(ccode);+}++/* ignore cache complexities for now */+temp=info.totalram-info.freeram-info.bufferram;+temp=temp*info.mem_unit;+temp=temp/1024;++used=temp;++print("ok 1 get runtime size # size = ");+print_num(used);+print(" K\n");++_exit(0);+}
This test shows the amount of memory used by the system.
Note that this is dependent on the user-space that is loaded
when this program runs. Optimally, this program would be
run as the init program itself.
The program is optimized for size itself, to avoid conflating
its own execution with that of the system software.
The code is compiled statically, with no stdlibs. On my x86_64 system,
this results in a statically linked binary of less than 5K.
Changes from v1:
- use more correct Copyright string in get_size.c
Signed-off-by: Tim Bird <tim.bird-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
---
tools/testing/selftests/Makefile | 1 +
tools/testing/selftests/size/Makefile | 21 +++++++
tools/testing/selftests/size/get_size.c | 105 ++++++++++++++++++++++++++++++++
3 files changed, 127 insertions(+)
create mode 100644 tools/testing/selftests/size/Makefile
create mode 100644 tools/testing/selftests/size/get_size.c
@@ -0,0 +1,105 @@+/*+*Copyright2014SonyMobileCommunicationsInc.+*+*LicensedunderthetermsoftheGNUGPLLicenseversion2+*+*Selftestforruntimesystemsize+*+*PrintstheamountofRAMthatthecurrentlyrunningsystemisusing.+*+*Thisprogramtriestobeassmallaspossibleitself,to+*avoidperturbingthesystemmemoryutilizationwithits+*ownexecution.Italsoattemptstohaveasfewdependencies+*onkernelfeaturesaspossible.+*+*Itshouldbestaticallylinked,withstartuplibsavoided.+*Itusesnolibrarycalls,andonlythefollowing3syscalls:+*sysinfo(),write(),and_exit()+*+*Foroutput,itavoidsprintf(whichinsomeClibraries+*haslargeexternaldependencies)byimplementingitsown+*strlen(),numberoutputandprint()routines.+*/++#include<sys/sysinfo.h>+#include<unistd.h>++#define STDOUT_FILENO 1++my_strlen(constchar*s)+{+intlen=0;++while(*s++)+len++;+returnlen;+}++/*+*num_to_str-putdigitsfromnuminto*s,lefttoright+*dothisbydividingthenumberbypowersof10+*thetrickypartistoomitleadingzeros+*don'tprintzerosuntilwe'vestartedprintinganynumbersatall+*/+staticvoidnum_to_str(unsignedlongnum,char*s)+{+unsignedlonglongtemp,div;+intstarted;++temp=num;+div=1000000000000000000LL;+started=0;+while(div){+if(temp/div||started){+*s++=(unsignedchar)(temp/div+'0');+started=1;+}+temp-=(temp/div)*div;+div/=10;+}+*s=0;+}++print_num(unsignedlongnum)+{+charnum_buf[30];++num_to_str(num,num_buf);+write(STDOUT_FILENO,num_buf,my_strlen(num_buf));+}++print(char*s)+{+write(STDOUT_FILENO,s,my_strlen(s));+}++voidmain(intargc,char**argv)+{+intccode;+unsignedlongused;+structsysinfoinfo;+unsignedlonglongtemp;++print("Testing system size.\n");+print("1..1\n");++ccode=sysinfo(&info);+if(ccode<0){+print("not ok 1 get size runtime size\n");+print("# could not get sysinfo\n");+_exit(ccode);+}++/* ignore cache complexities for now */+temp=info.totalram-info.freeram-info.bufferram;+temp=temp*info.mem_unit;+temp=temp/1024;++used=temp;++print("ok 1 get runtime size # size = ");+print_num(used);+print(" K\n");++_exit(0);+}
This test shows the amount of memory used by the system.
Note that this is dependent on the user-space that is loaded
when this program runs. Optimally, this program would be
run as the init program itself.
The program is optimized for size itself, to avoid conflating
its own execution with that of the system software.
The code is compiled statically, with no stdlibs. On my x86_64 system,
this results in a statically linked binary of less than 5K.
Changes from v1:
- use more correct Copyright string in get_size.c
Signed-off-by: Tim Bird <tim.bird-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
---
tools/testing/selftests/Makefile | 1 +
tools/testing/selftests/size/Makefile | 21 +++++++
tools/testing/selftests/size/get_size.c | 105 ++++++++++++++++++++++++++++++++
3 files changed, 127 insertions(+)
create mode 100644 tools/testing/selftests/size/Makefile
create mode 100644 tools/testing/selftests/size/get_size.c
Tim,
The test looks good, but you are missing .gitignore file.
Please add a .gitignore for the binary that gets generated to
avoid git status including the binary it in its output.
thanks,
-- Shuah
--
Shuah Khan
Sr. Linux Kernel Developer
Samsung Research America (Silicon Valley)
shuahkh-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org | (970) 217-8978
This test shows the amount of memory used by the system.
Note that this is dependent on the user-space that is loaded
when this program runs. Optimally, this program would be
run as the init program itself.
The program is optimized for size itself, to avoid conflating
its own execution with that of the system software.
The code is compiled statically, with no stdlibs. On my x86_64 system,
this results in a statically linked binary of less than 5K.
Changes from v1:
- use more correct Copyright string in get_size.c
Signed-off-by: Tim Bird <tim.bird-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
---
tools/testing/selftests/Makefile | 1 +
tools/testing/selftests/size/Makefile | 21 +++++++
tools/testing/selftests/size/get_size.c | 105 ++++++++++++++++++++++++++++++++
3 files changed, 127 insertions(+)
create mode 100644 tools/testing/selftests/size/Makefile
create mode 100644 tools/testing/selftests/size/get_size.c
Tim,
The test looks good, but you are missing .gitignore file.
Please add a .gitignore for the binary that gets generated to
avoid git status including the binary it in its output.
This test shows the amount of memory used by the system.
Note that this is dependent on the user-space that is loaded
when this program runs. Optimally, this program would be
run as the init program itself.
The program is optimized for size itself, to avoid conflating
its own execution with that of the system software.
The code is compiled statically, with no stdlibs. On my x86_64 system,
this results in a statically linked binary of less than 5K.
Changes from v2:
- add return values to print routines
- add .gitignore file
Changes from v1:
- use more correct Copyright string in get_size.c
Signed-off-by: Tim Bird <tim.bird-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
---
tools/testing/selftests/Makefile | 1 +
tools/testing/selftests/size/.gitignore | 1 +
tools/testing/selftests/size/Makefile | 21 +++++++
tools/testing/selftests/size/get_size.c | 105 ++++++++++++++++++++++++++++++++
4 files changed, 128 insertions(+)
create mode 100644 tools/testing/selftests/size/.gitignore
create mode 100644 tools/testing/selftests/size/Makefile
create mode 100644 tools/testing/selftests/size/get_size.c
@@ -0,0 +1,105 @@+/*+*Copyright2014Sony+*+*LicensedunderthetermsoftheGNUGPLLicenseversion2+*+*Selftestforruntimesystemsize+*+*PrintstheamountofRAMthatthecurrentlyrunningsystemisusing.+*+*Thisprogramtriestobeassmallaspossibleitself,to+*avoidperturbingthesystemmemoryutilizationwithits+*ownexecution.Italsoattemptstohaveasfewdependencies+*onkernelfeaturesaspossible.+*+*Itshouldbestaticallylinked,withstartuplibsavoided.+*Itusesnolibrarycalls,andonlythefollowing3syscalls:+*sysinfo(),write(),and_exit()+*+*Foroutput,itavoidsprintf(whichinsomeClibraries+*haslargeexternaldependencies)byimplementingitsown+*strlen(),numberoutputandprint()routines.+*/++#include<sys/sysinfo.h>+#include<unistd.h>++#define STDOUT_FILENO 1++intmy_strlen(constchar*s)+{+intlen=0;++while(*s++)+len++;+returnlen;+}++/*+*num_to_str-putdigitsfromnuminto*s,lefttoright+*dothisbydividingthenumberbypowersof10+*thetrickypartistoomitleadingzeros+*don'tprintzerosuntilwe'vestartedprintinganynumbersatall+*/+voidnum_to_str(unsignedlongnum,char*s)+{+unsignedlonglongtemp,div;+intstarted;++temp=num;+div=1000000000000000000LL;+started=0;+while(div){+if(temp/div||started){+*s++=(unsignedchar)(temp/div+'0');+started=1;+}+temp-=(temp/div)*div;+div/=10;+}+*s=0;+}++intprint_num(unsignedlongnum)+{+charnum_buf[30];++num_to_str(num,num_buf);+returnwrite(STDOUT_FILENO,num_buf,my_strlen(num_buf));+}++intprint(char*s)+{+returnwrite(STDOUT_FILENO,s,my_strlen(s));+}++voidmain(intargc,char**argv)+{+intccode;+unsignedlongused;+structsysinfoinfo;+unsignedlonglongtemp;++print("Testing system size.\n");+print("1..1\n");++ccode=sysinfo(&info);+if(ccode<0){+print("not ok 1 get size runtime size\n");+print("# could not get sysinfo\n");+_exit(ccode);+}++/* ignore cache complexities for now */+temp=info.totalram-info.freeram-info.bufferram;+temp=temp*info.mem_unit;+temp=temp/1024;++used=temp;++print("ok 1 get runtime size # size = ");+print_num(used);+print(" K\n");++_exit(0);+}
This test shows the amount of memory used by the system.
Note that this is dependent on the user-space that is loaded
when this program runs. Optimally, this program would be
run as the init program itself.
The program is optimized for size itself, to avoid conflating
its own execution with that of the system software.
The code is compiled statically, with no stdlibs. On my x86_64 system,
this results in a statically linked binary of less than 5K.
This following version information shouldn't be part of changelog.
Changes from v2:
- add return values to print routines
- add .gitignore file
Changes from v1:
- use more correct Copyright string in get_size.c
Signed-off-by: Tim Bird <tim.bird-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
---
@@ -0,0 +1,105 @@+/*+*Copyright2014Sony+*+*LicensedunderthetermsoftheGNUGPLLicenseversion2+*+*Selftestforruntimesystemsize+*+*PrintstheamountofRAMthatthecurrentlyrunningsystemisusing.+*+*Thisprogramtriestobeassmallaspossibleitself,to+*avoidperturbingthesystemmemoryutilizationwithits+*ownexecution.Italsoattemptstohaveasfewdependencies+*onkernelfeaturesaspossible.+*+*Itshouldbestaticallylinked,withstartuplibsavoided.+*Itusesnolibrarycalls,andonlythefollowing3syscalls:+*sysinfo(),write(),and_exit()+*+*Foroutput,itavoidsprintf(whichinsomeClibraries+*haslargeexternaldependencies)byimplementingitsown+*strlen(),numberoutputandprint()routines.+*/++#include<sys/sysinfo.h>+#include<unistd.h>++#define STDOUT_FILENO 1++intmy_strlen(constchar*s)+{+intlen=0;++while(*s++)+len++;+returnlen;+}++/*+*num_to_str-putdigitsfromnuminto*s,lefttoright+*dothisbydividingthenumberbypowersof10+*thetrickypartistoomitleadingzeros+*don'tprintzerosuntilwe'vestartedprintinganynumbersatall+*/+voidnum_to_str(unsignedlongnum,char*s)+{+unsignedlonglongtemp,div;+intstarted;++temp=num;+div=1000000000000000000LL;+started=0;+while(div){+if(temp/div||started){+*s++=(unsignedchar)(temp/div+'0');+started=1;+}+temp-=(temp/div)*div;+div/=10;+}+*s=0;+}++intprint_num(unsignedlongnum)+{+charnum_buf[30];++num_to_str(num,num_buf);+returnwrite(STDOUT_FILENO,num_buf,my_strlen(num_buf));+}++intprint(char*s)+{+returnwrite(STDOUT_FILENO,s,my_strlen(s));+}++voidmain(intargc,char**argv)+{+intccode;+unsignedlongused;+structsysinfoinfo;+unsignedlonglongtemp;++print("Testing system size.\n");+print("1..1\n");
I ran this test and the reporting could be improved.
Could you change the above to say
System RAM in use instead of system size. Also can you also
print total RAM and other information you already have:
Maybe something along the lines of:
System RAM report (units Kilobytes):
Total:
Free:
Bufferram:
In use:
I would remove the print("1..1\n");
+
+ ccode = sysinfo(&info);
+ if (ccode < 0) {
+ print("not ok 1 get size runtime size\n");
+ print("# could not get sysinfo\n");
+ _exit(ccode);
+ }
+
+ /* ignore cache complexities for now */
+ temp = info.totalram - info.freeram - info.bufferram;
+ temp = temp * info.mem_unit;
+ temp = temp / 1024;
+
+ used = temp;
+
+ print("ok 1 get runtime size # size = ");
+ print_num(used);
+ print(" K\n");
Please see above. You can get rid of print(" K\n"); at the end.
Sorry for not giving this feedback earlier. The not so clear
reporting aspect stood out for me after running the test.
thanks,
-- Shuah
--
Shuah Khan
Sr. Linux Kernel Developer
Samsung Research America (Silicon Valley)
shuahkh-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org | (970) 217-8978
This test shows the amount of memory used by the system.
Note that this is dependent on the user-space that is loaded
when this program runs. Optimally, this program would be
run as the init program itself.
The program is optimized for size itself, to avoid conflating
its own execution with that of the system software.
The code is compiled statically, with no stdlibs. On my x86_64 system,
this results in a statically linked binary of less than 5K.
This following version information shouldn't be part of changelog.
quoted
Changes from v2:
- add return values to print routines
- add .gitignore file
Changes from v1:
- use more correct Copyright string in get_size.c
Signed-off-by: Tim Bird <tim.bird-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
---
@@ -0,0 +1,105 @@+/*+*Copyright2014Sony+*+*LicensedunderthetermsoftheGNUGPLLicenseversion2+*+*Selftestforruntimesystemsize+*+*PrintstheamountofRAMthatthecurrentlyrunningsystemisusing.+*+*Thisprogramtriestobeassmallaspossibleitself,to+*avoidperturbingthesystemmemoryutilizationwithits+*ownexecution.Italsoattemptstohaveasfewdependencies+*onkernelfeaturesaspossible.+*+*Itshouldbestaticallylinked,withstartuplibsavoided.+*Itusesnolibrarycalls,andonlythefollowing3syscalls:+*sysinfo(),write(),and_exit()+*+*Foroutput,itavoidsprintf(whichinsomeClibraries+*haslargeexternaldependencies)byimplementingitsown+*strlen(),numberoutputandprint()routines.+*/++#include<sys/sysinfo.h>+#include<unistd.h>++#define STDOUT_FILENO 1++intmy_strlen(constchar*s)+{+intlen=0;++while(*s++)+len++;+returnlen;+}++/*+*num_to_str-putdigitsfromnuminto*s,lefttoright+*dothisbydividingthenumberbypowersof10+*thetrickypartistoomitleadingzeros+*don'tprintzerosuntilwe'vestartedprintinganynumbersatall+*/+voidnum_to_str(unsignedlongnum,char*s)+{+unsignedlonglongtemp,div;+intstarted;++temp=num;+div=1000000000000000000LL;+started=0;+while(div){+if(temp/div||started){+*s++=(unsignedchar)(temp/div+'0');+started=1;+}+temp-=(temp/div)*div;+div/=10;+}+*s=0;+}++intprint_num(unsignedlongnum)+{+charnum_buf[30];++num_to_str(num,num_buf);+returnwrite(STDOUT_FILENO,num_buf,my_strlen(num_buf));+}++intprint(char*s)+{+returnwrite(STDOUT_FILENO,s,my_strlen(s));+}++voidmain(intargc,char**argv)+{+intccode;+unsignedlongused;+structsysinfoinfo;+unsignedlonglongtemp;++print("Testing system size.\n");+print("1..1\n");
I ran this test and the reporting could be improved.
Could you change the above to say
System RAM in use instead of system size.
I'll have to think about this. I'm not sure what the
correct phrasing would be for XIP systems (for which part of
the kernel resides in flash, not RAM, maybe "memory"?)
Also can you also
print total RAM and other information you already have:
I can print it as part of total output, but for regression
testing and automation I want the tool to have a single
number result as output (well, one number relating to runtime
size, and I'm considering adding one number relating
to compile-time size.)
Maybe something along the lines of:
System RAM report (units Kilobytes):
Total:
Free:
Bufferram:
In use:
I would remove the print("1..1\n");
This is part of the TAP output format.
Is there any (other) output format being standardized for selftest
programs?
TAP allows me to output more human-readable information to go
along with the "official" result, but I'd like to keep the
official result in TAP format so it can be handled by automated
tools. Maybe it would be best to output both.
I'll try to make a counter-proposal tomorrow that we can discus.
quoted
+
+ ccode = sysinfo(&info);
+ if (ccode < 0) {
+ print("not ok 1 get size runtime size\n");
+ print("# could not get sysinfo\n");
+ _exit(ccode);
+ }
+
+ /* ignore cache complexities for now */
+ temp = info.totalram - info.freeram - info.bufferram;
+ temp = temp * info.mem_unit;
+ temp = temp / 1024;
+
+ used = temp;
+
+ print("ok 1 get runtime size # size = ");
+ print_num(used);
+ print(" K\n");
Please see above. You can get rid of print(" K\n"); at the end.
Sorry for not giving this feedback earlier. The not so clear
reporting aspect stood out for me after running the test.
No problem. Thanks for looking at it.
I have some additional changes, based on feedback from Josh Triplett,
so look for a v4 tomorrow.
-- Tim