Chinaunix首页 | 论坛 | 博客
  • 博客访问: 327094
  • 博文数量: 81
  • 博客积分: 1810
  • 博客等级: 上尉
  • 技术积分: 725
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-25 17:38
文章分类

全部博文(81)

文章存档

2016年(4)

2015年(11)

2014年(16)

2013年(37)

2012年(11)

2011年(2)

我的朋友

分类: 网络与安全

2014-04-16 20:29:39

原文地址:memtester测试 作者:gron

 
 运行memteste非常简单,作为root
./ memtester [runs]
:内存大小,单位M [runs]:运行次数
 

1) 工具描述


Memtester主要是捕获内存错误和一直处于很高或者很低的坏位, 其测试的主要项目有随机值,异或比较,减法,乘法,除法,与或运算等等. 通过给定测试内存的大小和次数, 可以对系统现有的内存进行上面项目的测试.


2) 下载安装


下载地址:

# cd /orahome/wangnc/os/

# rz

# tar zxvf memtester-4.0.8.tar.gz

# cd memtester-4.0.8

# make all (这样在当前的目录下会生成memtester的可执行文件)

# make install (如果需要可以通过install, 把可执行文件和man文件拷到/usr/local/下)


3) 简单测试


# memtester [ITERATIONS]

MEMORY是要测试的内存的大小, 单位是MB;

ITERATIONS是测试次数. 如果没有指定测试次数, 那么测试会一直进行, 直到用户终止.

# more README (查看帮助)

# man memtester (查看man)

# ./memtester 100 1 > /tmp/memtest.log &

# tail -100f /tmp/memtest.log

memtester version 4.0.8 (64-bit)

Copyright (C) 2007 Charles Cazabon.

Licensed under the GNU General Public License version 2 (only).

pagesize is 4096

pagesizemask is 0xfffffffffffff000

want 100MB (104857600 bytes)

got   100MB (104857600 bytes), trying mlock ...locked.

Loop 1/3:

   Stuck Address        : ok         

   Random Value         : ok

   Compare XOR          : ok

   Compare SUB          : ok

   Compare MUL          : ok

   Compare DIV          : ok

   Compare OR           : ok

   Compare AND          : ok

   Sequential Increment: ok

   Solid Bits           : ok         

   Block Sequential     : ok         

   Checkerboard         : ok         

   Bit Spread           : ok         

   Bit Flip             : ok         

   Walking Ones         : ok         

   Walking Zeroes       : ok       

  

4) 使用脚本:
 
 
   这样我们就可以对单颗CPU的机器进行测试,查看内存是否足够稳定。但如果我有多颗CPU和较大的memory呢?最简单的方法是多开几个终端,同时运行memtester,每个CPU分配同样大小的内存。还有一种方法可以使用Baif编写的一个脚本memtester-multi.sh,位置放在memtester-4.0.7下就可以了。这个脚本只在linux下有效!
 
**********************************************************************************************
#!/bin/sh
# Memory Tester Scripts

# by Baif
# version = date
VERSION="Fri Oct 19 11:56:57 CST 2007"

# trap for irruptions
MEMTESTER=${PWD}/memtester
PPIDKILL=$$
SIDKILL=$$
trap "pkill -9 -P ${PPIDKILL};kill -9 $$" INT
trap "pkill -9 -P ${PPIDKILL};kill -9 $$" KILL


cat <<-EOF_vpps >&2

Version: ${VERSION}
PID: $$
PPIDKILL: ${PPIDKILL}
SIDKILL: ${PPIDKILL}

EOF_vpps

CORE_NUM=$(grep -i ^processor /proc/cpuinfo|wc -l)
MEMTESTERCOPY=${CORE_NUM}
MEM_TOTAL_K=$(awk '/^MemTotal/{print $2}' /proc/meminfo)
MEM_RESERVE_PERCENTAGE=$((1000*50/1024)) # 95%

MEM_RESERVED=$((MEM_TOTAL_K/1024*MEM_RESERVE_PERCENTAGE/1000))
MEM_TOTAL_TOBETESTED=$((MEM_TOTAL_K/1024-MEM_RESERVED))
MEM_PER_COPY=$((MEM_TOTAL_TOBETESTED/MEMTESTERCOPY))

RUN_DURATION_TIME=0
RUN_LOOPS=-1
RUN_DURATION_TIME_FLAG=0
RUN_LOOPS_FLAG=0
DDPERCOPY_TIME=6s

LOGDIR=/tmp/memtester-log-${$}
mkdir -p ${LOGDIR}

show_help ()
{
cat <<-EOFshow_HELP >&2

Version: ${VERSION}

Usage: $(basename ${0})
-r Directory: the root location of memtester binary file
-c NUMBER: the copies of memtester should be run
-m NUMBER: how many memory should be tested totally (in MB)
-t TIME: duration mode, how long will the tests go
-l NUMBER: loops mode,how many loops will each memtester should go

The option -t and -l are exclusive, which means tests could work
only with 1. duration mode or 2. loops mode

RUN 4 copies memtester with in 24 hours, to test total 4000 MB memory:

$(basename ${0}) -t 24h -c 4 -m 4000

RUN 2 copies memtester with in 1 hours, to test total 4000 MB memory:

$(basename ${0}) -t 1h -c 4 -m 4000

RUN 4 copies memtester with in 2 loops, to test total 3600 MB memory:

$(basename ${0}) -l 2 -c 4 -m 3600

-V/-h/-H: show this info.

EOFshow_HELP

exit 0
}

while getopts :c:m:t:l:r:p:hHVvx OPTION
do
case ${OPTION} in
c)
#echo "-c ${OPTARG}"
MEMTESTERCOPY=${OPTARG}
;;
m)
#echo "-m ${OPTARG} MB"
MEM_TOTAL_TOBETESTED=${OPTARG}
MEM_RESERVED=$((MEM_TOTAL_K/1024-MEM_TOTAL_TOBETESTED))
;;
t)
#echo "-t ${OPTARG}"
[ 0 -ne ${RUN_LOOPS_FLAG} ] && echo "-t and -l are exclusive." && exit 222
RUN_DURATION_TIME=${OPTARG}
RUN_DURATION_TIME_FLAG=1
;;
l)
#echo "-l ${OPTARG}"
[ 0 -ne ${RUN_DURATION_TIME_FLAG} ] && echo && echo "-t and -l are exclusive." && show_help && echo && exit 223
RUN_LOOPS=${OPTARG};
RUN_LOOPS_FLAG=1
;;
d)
#echo "-r ${OPTARG}"
MEMTESTER=${OPTARG}/memtester
;;
p)
#echo "-p ${OPTARG}"
MEMTESTER=${OPTARG}
;;
V|h|H)
show_help
;;
v)
set -v
;;
x)
set -x
;;
?) echo "Error...";
echo "?Unknown args..."
exit 224
;;
*) #echo "*Unknown args..."
esac
done
#exit
[ 0 -eq ${RUN_DURATION_TIME_FLAG} ] && [ 0 -eq ${RUN_LOOPS_FLAG} ] && echo && echo "Please specified which mode should we run... -t or -l" && show_help && echo && exit 225

MEM_PER_COPY=$((MEM_TOTAL_TOBETESTED/MEMTESTERCOPY))

echo "Mem total: " $((MEM_TOTAL_K/1024)) MB
echo "Core total: "${CORE_NUM}
echo "Memtester copys: " ${MEMTESTERCOPY}
echo "Mem per copy: "${MEM_PER_COPY}
echo "Mem total to used: "${MEM_TOTAL_TOBETESTED} MB
if [ ${MEM_RESERVED} -lt 1 ];
then
echo "Mem reserved: -- No more memory reserved..."
else
echo "Mem reserved: "${MEM_RESERVED} MB
fi
#exit


# GOGOGO
if [ 0 -ne ${RUN_DURATION_TIME_FLAG} ]; then
echo "Run within a duration: ${RUN_DURATION_TIME}"
elif [ 0 -ne ${RUN_LOOPS_FLAG} ];
then
echo "Run within a loop: ${RUN_LOOPS}"
fi
echo "Working directory: " $PWD
echo "Memtester: " ${MEMTESTER}
echo "LOGs directory: " $LOGDIR
echo
echo -n "Jobs started at date: "
date #+%Y/%m/%d\ %H:%M
echo
#exit

########################
# Run testing within a duration time.
if [ 0 -ne ${RUN_DURATION_TIME_FLAG} ]
then
# prepareing the sleeping killers
sleep ${RUN_DURATION_TIME}
echo -n "End of testing(TIMEOUT)... "
echo "KILL CHILD" && kill -9 $(pgrep -P ${PPIDKILL} memtester) && echo "Childen processes - KILLED."
# attention to how the memtesters are forked...
echo "KILL PARENT" && kill $$ && echo "KILLED." &
echo "Finished the memtester"
echo -n "Jobs finished at date: "
date #+%Y/%m/%d\ %H:%M

fi &

echo -n "Waiting (PID: $$) for ${MEMTESTERCOPY} memtesters(${MEM_PER_COPY}MB for each). "
if [ 0 -ne ${RUN_DURATION_TIME_FLAG} ];
then
echo -n "For time: ${RUN_DURATION_TIME} "
fi
if [ 0 -ne ${RUN_LOOPS_FLAG} ];
then
echo -n "For loops: ${RUN_LOOPS} "
fi
echo "..."


while true
do
MEMTESTER_NUM=0

echo -n "{"
while [ ${MEMTESTER_NUM} -lt ${MEMTESTERCOPY} ]
do
echo -n " ${MEMTESTER_NUM} "

if [ 0 -ne ${RUN_DURATION_TIME_FLAG} ]
then
RUN_LOOPS=0
fi

${MEMTESTER} ${MEM_PER_COPY} ${RUN_LOOPS} 2>&1 >> ${LOGDIR}/${MEMTESTER_NUM}.log &
# set loops = 0 to make memtester run loop infinitely...
# .pogo version will run only one loop by default

sleep ${DDPERCOPY_TIME}
MEMTESTER_NUM=$(expr $MEMTESTER_NUM + 1)
done
echo -n "}"
wait

[ 0 -ne ${RUN_LOOPS_FLAG} ] && break
# memtesters' loops...
done

########################

echo
echo -n "End of testing(Excution ended)... "
pkill -9 -P ${PPIDKILL}
kill $$
echo "Finished the memtester"
echo -n "Jobs finished at date: "
date #+%Y/%m/%d\ %H:%M
 
**********************************************************************************************
运行这个脚本
sh memtester-multi.sh –c -l -m
-c:运行几个memtester
-l: 运行几次
-m:测试多大的内存,直接填测试总数即可,程序会自动分配个平均值给每个memtester,这样省去我们自己的计算,也不用多开几个终端了,单位MB
例如我有一个4颗CPU,32G内存的机器,我就可以这样运行

sh memtester-multi.sh –c 4 –l 1 –m 3100

大家可以看这个脚本中还可以限定时间,例如我想运行24个小时

sh memtester-multi.sh –t 24h -c 4 –m 3100
阅读(13667) | 评论(0) | 转发(0) |
0

上一篇:unsigned char,char,signed char

下一篇:X-macro

给主人留下些什么吧!~~