WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

RE: [Xen-devel] Balloon tests

To: "Paul Larson" <plars@xxxxxxxxxxxxxxxxxxxx>, "xen-devel" <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: RE: [Xen-devel] Balloon tests
From: "Ian Pratt" <m+Ian.Pratt@xxxxxxxxxxxx>
Date: Fri, 5 Aug 2005 18:36:14 +0100
Delivery-date: Fri, 05 Aug 2005 17:34:52 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
Thread-index: AcWZ343X1ghp8P9BSM2M3WVdQj3dCAABEBxg
Thread-topic: [Xen-devel] Balloon tests
 
> I've submitted these before, and there were no comments.  Any 
> suggestions for addition tests on the balloon driver would be 
> appreciated.  Here it is again as a patch putting them under 
> /tools/tests/balloon.

Unrelated, but are we going to move /proc/xen/balloon to somewhere under
/sys e.g. /sys/xen/mem_target or something?

Ian

 
> --
> Thanks,
> Paul Larson
> plars@xxxxxxxxxxxxxxxxxxxx
> http://www.linuxtestproject.org
> 
> # HG changeset patch
> # User root@xxxxxxxxxxxxxxxxxxxxxxxx
> # Node ID fa47e95d40dc1cd96ff54555284efd60bbdd6406
> # Parent  b63577ff53a3161ac73b55e0aa87803e76c8bde5
> Add simple set of tests for balloon driver
> 
> These can be executed individually, or with make check from 
> the balloon directory.  The ballon06 test is skipped in make 
> check for the time being, and has a big warning and 10 second 
> delay when you run it standalone since it exposes the system 
> hang bug described in bug #145.
> 
> Signed-off-by: Paul Larson <pl@xxxxxxxxxx>
> 
> diff -r b63577ff53a3 -r fa47e95d40dc tools/tests/balloon/Makefile
> --- /dev/null Fri Aug  5 14:57:43 2005
> +++ b/tools/tests/balloon/Makefile    Fri Aug  5 16:57:07 2005
> @@ -0,0 +1,27 @@
> +CFLAGS=-g -Wall -Werror
> +
> +PROGS=balloon07 balloon08 balloon09 memsteal
> +
> +#balloon06 is left out on purpose due to a known, fatal bug
> +TESTS=balloon01 balloon02 balloon03 balloon04 balloon05 balloon07 \
> +      balloon08 balloon09
> +
> +all: $(PROGS)
> +
> +balloon07: balloon07.o
> +balloon08: balloon08.o
> +balloon09: balloon09.o
> +memsteal: memsteal.o
> +
> +clean:
> +     $(RM) *.o $(PROGS)
> +
> +check: all
> +     for test in $(TESTS); do ./$$test; done
> +
> +%.o: %.c
> +     $(CC) -c $(CFLAGS) -o $@ $^
> +
> +%: %.o
> +     $(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS)
> +
> diff -r b63577ff53a3 -r fa47e95d40dc tools/tests/balloon/balloon01
> --- /dev/null Fri Aug  5 14:57:43 2005
> +++ b/tools/tests/balloon/balloon01   Fri Aug  5 16:57:07 2005
> @@ -0,0 +1,31 @@
> +#!/bin/bash
> +
> +#
> +# Copyright (c) International Business Machines  Corp., 2005 # This 
> +program is free software;  you can redistribute it and/or 
> modify # it 
> +under the terms of the GNU General Public License as 
> published by # the 
> +Free Software Foundation; either version 2 of the License, or # (at 
> +your option) any later version.
> +#
> +# This program is distributed in the hope that it will be 
> useful, # but 
> +WITHOUT ANY WARRANTY;  without even the implied warranty of # 
> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See # the GNU 
> +General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public 
> License # 
> +along with this program;  if not, write to the Free Software # 
> +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
> USA
> +#
> +# Test name: balloon01
> +# Author: Paul Larson <pl@xxxxxxxxxx>
> +# Description: Test read from /proc/xen/balloon
> +
> +TESTNAME=balloon01
> +
> +cat /proc/xen/balloon &> /dev/null
> +if [ $? == 0 ]
> +then
> +     echo "$TESTNAME PASS: read from /proc/xen/balloon"
> +else
> +     echo "$TESTNAME FAIL: read from /proc/xen/balloon"
> +fi
> diff -r b63577ff53a3 -r fa47e95d40dc tools/tests/balloon/balloon02
> --- /dev/null Fri Aug  5 14:57:43 2005
> +++ b/tools/tests/balloon/balloon02   Fri Aug  5 16:57:07 2005
> @@ -0,0 +1,43 @@
> +#!/bin/bash
> +
> +#
> +# Copyright (c) International Business Machines  Corp., 2005 # This 
> +program is free software;  you can redistribute it and/or 
> modify # it 
> +under the terms of the GNU General Public License as 
> published by # the 
> +Free Software Foundation; either version 2 of the License, or # (at 
> +your option) any later version.
> +#
> +# This program is distributed in the hope that it will be 
> useful, # but 
> +WITHOUT ANY WARRANTY;  without even the implied warranty of # 
> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See # the GNU 
> +General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public 
> License # 
> +along with this program;  if not, write to the Free Software # 
> +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
> USA
> +#
> +# Test name: balloon02
> +# Author: Paul Larson <pl@xxxxxxxxxx>
> +# Description: Echo a number higher than current requested allocation
> to 
> +#           /proc/xen/balloon, cat balloon and see that requested 
> +#           target changed.
> +
> +TESTNAME=balloon02
> +
> +#Units seem to currently be in kB
> +old_alloc=`cat /proc/xen/balloon |grep Requested |awk -F ' +' '{print
> $3}'`
> +
> +new_alloc=$(( $old_alloc + 4096 ))
> +echo $[new_alloc]K > /proc/xen/balloon
> +check_alloc=`cat /proc/xen/balloon |grep Requested |awk -F ' 
> +' '{print
> $3}'`
> +
> +#cleanup before checking the value and exiting echo $[old_alloc]K > 
> +/proc/xen/balloon
> +
> +if [ $check_alloc == $new_alloc ]
> +then
> +     echo "$TESTNAME PASS: Requested allocation increased 
> from $old_alloc"\
> +             "kB to $new_alloc kB"
> +else
> +     echo "$TESTNAME FAIL: increase Requested allocation by 4k"
> +fi
> diff -r b63577ff53a3 -r fa47e95d40dc tools/tests/balloon/balloon03
> --- /dev/null Fri Aug  5 14:57:43 2005
> +++ b/tools/tests/balloon/balloon03   Fri Aug  5 16:57:07 2005
> @@ -0,0 +1,43 @@
> +#!/bin/bash
> +
> +#
> +# Copyright (c) International Business Machines  Corp., 2005 # This 
> +program is free software;  you can redistribute it and/or 
> modify # it 
> +under the terms of the GNU General Public License as 
> published by # the 
> +Free Software Foundation; either version 2 of the License, or # (at 
> +your option) any later version.
> +#
> +# This program is distributed in the hope that it will be 
> useful, # but 
> +WITHOUT ANY WARRANTY;  without even the implied warranty of # 
> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See # the GNU 
> +General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public 
> License # 
> +along with this program;  if not, write to the Free Software # 
> +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
> USA
> +#
> +# Test name: balloon03
> +# Author: Paul Larson <pl@xxxxxxxxxx>
> +# Description: Echo a number lower than current requested allocation
> to 
> +#           /proc/xen/balloon, cat balloon and see that requested 
> +#           target changed.
> +
> +TESTNAME=balloon03
> +
> +#Units seem to currently be in kB
> +old_alloc=`cat /proc/xen/balloon |grep Requested |awk -F ' +' '{print
> $3}'`
> +
> +new_alloc=$(( $old_alloc - 4096 ))
> +echo $[new_alloc]K > /proc/xen/balloon
> +check_alloc=`cat /proc/xen/balloon |grep Requested |awk -F ' 
> +' '{print
> $3}'`
> +
> +#cleanup before checking the value and exiting echo $[old_alloc]K > 
> +/proc/xen/balloon
> +
> +if [ $check_alloc == $new_alloc ]
> +then
> +     echo "$TESTNAME PASS: Requested allocation decreased 
> from $old_alloc"\
> +             "kB to $new_alloc kB"
> +else
> +     echo "$TESTNAME FAIL: decrease Requested allocation by 4k"
> +fi
> diff -r b63577ff53a3 -r fa47e95d40dc tools/tests/balloon/balloon04
> --- /dev/null Fri Aug  5 14:57:43 2005
> +++ b/tools/tests/balloon/balloon04   Fri Aug  5 16:57:07 2005
> @@ -0,0 +1,42 @@
> +#!/bin/bash
> +
> +#
> +# Copyright (c) International Business Machines  Corp., 2005 # This 
> +program is free software;  you can redistribute it and/or 
> modify # it 
> +under the terms of the GNU General Public License as 
> published by # the 
> +Free Software Foundation; either version 2 of the License, or # (at 
> +your option) any later version.
> +#
> +# This program is distributed in the hope that it will be 
> useful, # but 
> +WITHOUT ANY WARRANTY;  without even the implied warranty of # 
> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See # the GNU 
> +General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public 
> License # 
> +along with this program;  if not, write to the Free Software # 
> +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
> USA
> +#
> +# Test name: balloon04
> +# Author: Paul Larson <pl@xxxxxxxxxx>
> +# Description: Allocate some memory for the domain, then use
> +#              /proc/xen/balloon to reduce available memory to less
> than
> +#              what is allocated
> +
> +TESTNAME=balloon04
> +
> +old_alloc=`cat /proc/xen/balloon |grep Requested |awk -F ' +' '{print
> $3}'`
> +
> +#Allocating 128 MB, reducing memory to 120 MB new_alloc=$(( 
> 120 * 1024 
> +)) ./memsteal 128& cpid=$!
> +sleep 2
> +
> +echo $[new_alloc]K > /proc/xen/balloon
> +#wait a moment for it to settle
> +sleep 3
> +echo $[old_alloc]K > /proc/xen/balloon
> +kill $cpid
> +
> +#If you make it this far, the test passed echo "$TESTNAME PASS: 
> +Requested allocation reduced to $new_alloc kB"
> diff -r b63577ff53a3 -r fa47e95d40dc tools/tests/balloon/balloon05
> --- /dev/null Fri Aug  5 14:57:43 2005
> +++ b/tools/tests/balloon/balloon05   Fri Aug  5 16:57:07 2005
> @@ -0,0 +1,45 @@
> +#!/bin/bash
> +
> +#
> +# Copyright (c) International Business Machines  Corp., 2005 # This 
> +program is free software;  you can redistribute it and/or 
> modify # it 
> +under the terms of the GNU General Public License as 
> published by # the 
> +Free Software Foundation; either version 2 of the License, or # (at 
> +your option) any later version.
> +#
> +# This program is distributed in the hope that it will be 
> useful, # but 
> +WITHOUT ANY WARRANTY;  without even the implied warranty of # 
> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See # the GNU 
> +General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public 
> License # 
> +along with this program;  if not, write to the Free Software # 
> +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
> USA
> +#
> +# Test name: balloon05
> +# Author: Paul Larson <pl@xxxxxxxxxx>
> +# Description: Try to give /proc/xen/balloon a value larger than the 
> +#           available RAM in the system.
> +
> +TESTNAME=balloon05
> +
> +#Units seem to currently be in kB
> +old_alloc=`cat /proc/xen/balloon |grep Requested |awk -F ' +' '{print
> $3}'`
> +
> +#If you have more than 70GB, either change this number or 
> take some of
> that 
> +#out and send it my way :)
> +new_alloc=73400320
> +
> +echo $[new_alloc]K > /proc/xen/balloon
> +check_alloc=`cat /proc/xen/balloon |grep Requested |awk -F ' 
> +' '{print
> $3}'`
> +
> +#cleanup before checking the value and exiting echo $[old_alloc]K > 
> +/proc/xen/balloon
> +
> +if [ $check_alloc == $new_alloc ]
> +then
> +     echo "$TESTNAME PASS: Requested alloc. increased from 
> $old_alloc"\
> +             "kB to $new_alloc kB"
> +else
> +     echo "$TESTNAME FAIL: increase Requested allocation to 70GB"
> +fi
> diff -r b63577ff53a3 -r fa47e95d40dc tools/tests/balloon/balloon06
> --- /dev/null Fri Aug  5 14:57:43 2005
> +++ b/tools/tests/balloon/balloon06   Fri Aug  5 16:57:07 2005
> @@ -0,0 +1,39 @@
> +#!/bin/bash
> +
> +#
> +# Copyright (c) International Business Machines  Corp., 2005 # This 
> +program is free software;  you can redistribute it and/or 
> modify # it 
> +under the terms of the GNU General Public License as 
> published by # the 
> +Free Software Foundation; either version 2 of the License, or # (at 
> +your option) any later version.
> +#
> +# This program is distributed in the hope that it will be 
> useful, # but 
> +WITHOUT ANY WARRANTY;  without even the implied warranty of # 
> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See # the GNU 
> +General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public 
> License # 
> +along with this program;  if not, write to the Free Software # 
> +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
> USA
> +#
> +# Test name: balloon06
> +# Author: Paul Larson <pl@xxxxxxxxxx>
> +# Description: Try to give /proc/xen/balloon a value way too 
> low, such
> as 4k
> +#
> +# Warning: Known to crash at the time this was written
> +
> +TESTNAME=balloon06
> +
> +old_alloc=`cat /proc/xen/balloon |grep Requested |awk -F ' +' '{print
> $3}'`
> +new_alloc=4
> +
> +echo
> '*************************************************************
> *********'
> +echo '* Warning!!! About to run a test that is known to hang or crash
> *'
> +echo '* the system! Abort now, echo if you wish, sleeping for 10
> seconds.  *'
> +echo
> '*************************************************************
> *********'
> +sleep 10
> +
> +echo $[new_alloc]K > /proc/xen/balloon
> +sleep 3
> +echo $[old_alloc]K > /proc/xen/balloon
> +echo "$TESTNAME PASS: Requested allocation reduced to $new_alloc kB"
> diff -r b63577ff53a3 -r fa47e95d40dc tools/tests/balloon/balloon07.c
> --- /dev/null Fri Aug  5 14:57:43 2005
> +++ b/tools/tests/balloon/balloon07.c Fri Aug  5 16:57:07 2005
> @@ -0,0 +1,68 @@
> +/*
> + *
> + * Copyright (c) International Business Machines  Corp., 2005
> + * This program is free software;  you can redistribute it and/or
> modify
> + * it under the terms of the GNU General Public License as 
> published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY;  without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
> + * the GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program;  if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 
> 02111-1307
> USA
> + *
> + * Test name: balloon07
> + * Author: Paul Larson <pl@xxxxxxxxxx>
> + * Description: Open /proc/xen/balloon as non-root user, 
> expect -EACCES 
> + */
> +
> +#include <errno.h>
> +#include <fcntl.h>
> +#include <pwd.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <unistd.h>
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +
> +#define TESTNAME "balloon07"
> +
> +int main(void)
> +{
> +     int fd;
> +     int err;
> +     char username[] = "nobody";
> +     struct passwd *user;
> +
> +     user = getpwnam(username);
> +
> +     if (setreuid(user->pw_uid, user->pw_uid) == -1) {
> +             printf("%s FAIL: setreuid(): %s\n",TESTNAME, 
> strerror(errno));
> +             exit(1);
> +     }
> +
> +     fd = open("/proc/xen/balloon", O_RDWR);
> +     err = errno;
> +     if (fd != -1) {
> +             printf("%s FAIL: Write to /proc/xen/balloon as 
> non-root "
> +                    "user succeeded\n", TESTNAME);
> +             close(fd);
> +             exit(1);
> +     }
> +     if (err != 13) {
> +             printf("%s FAIL: Write to /proc/xen/balloon as 
> non-root "
> +                    "got errno %d, expected 13\n", TESTNAME, err);
> +             close(fd);
> +             exit(1);
> +     }
> +     printf("%s PASS: Write to /proc/xen/balloon as non-root 
> user failed "
> +            "with -EACCES\n", TESTNAME);
> +     close(fd);
> +     exit(0);
> +}
> +
> diff -r b63577ff53a3 -r fa47e95d40dc tools/tests/balloon/balloon08.c
> --- /dev/null Fri Aug  5 14:57:43 2005
> +++ b/tools/tests/balloon/balloon08.c Fri Aug  5 16:57:07 2005
> @@ -0,0 +1,64 @@
> +/*
> + *
> + * Copyright (c) International Business Machines  Corp., 2005
> + * This program is free software;  you can redistribute it and/or
> modify
> + * it under the terms of the GNU General Public License as 
> published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY;  without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
> + * the GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program;  if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 
> 02111-1307
> USA
> + *
> + * Test name: balloon08
> + * Author: Paul Larson <pl@xxxxxxxxxx>
> + * Description: Write 1 byte to /proc/xen/balloon, expect -EBADMSG */
> +
> +#include <errno.h>
> +#include <fcntl.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <unistd.h>
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +
> +#define TESTNAME "balloon08"
> +
> +int main(void)
> +{
> +     int fd;
> +     int ret, err;
> +
> +     fd = open("/proc/xen/balloon", O_RDWR);
> +     if (fd == -1) {
> +             printf("%s FAIL: failed to open 
> /proc/xen/balloon, %s\n",
> +                     TESTNAME, strerror(errno));
> +             exit(1);
> +     }
> +     ret = write(fd, "a", 1);
> +     err = errno;
> +     if (ret != -1) {
> +             printf("%s FAIL: Write 1 byte to 
> /proc/xen/balloon succeeded\n",
> +                     TESTNAME);
> +             close(fd);
> +             exit(1);
> +     }
> +     if (err != 74) {
> +             printf("%s FAIL: Write 1 byte got errno %d, 
> expected 74\n",
> +                     TESTNAME, err);
> +             close(fd);
> +             exit(1);
> +     }
> +     printf("%s PASS: Write 1 byte failed with -EBADMSG\n",
> +             TESTNAME);
> +     close(fd);
> +     exit(0);
> +}
> +
> diff -r b63577ff53a3 -r fa47e95d40dc tools/tests/balloon/balloon09.c
> --- /dev/null Fri Aug  5 14:57:43 2005
> +++ b/tools/tests/balloon/balloon09.c Fri Aug  5 16:57:07 2005
> @@ -0,0 +1,70 @@
> +/*
> + *
> + * Copyright (c) International Business Machines  Corp., 2005
> + * This program is free software;  you can redistribute it and/or
> modify
> + * it under the terms of the GNU General Public License as 
> published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY;  without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
> + * the GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program;  if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 
> 02111-1307
> USA
> + *
> + * Test name: balloon09
> + * Author: Paul Larson <pl@xxxxxxxxxx>
> + * Description: Write >64 bytes to /proc/xen/balloon, expect 
> -EFBIG */
> +
> +#include <errno.h>
> +#include <fcntl.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <unistd.h>
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +
> +#define TESTNAME "balloon09"
> +#define STRSIZE 100
> +
> +int main(void)
> +{
> +     int fd;
> +     int ret, err, i;
> +     char str[STRSIZE];
> +
> +     for(i=0;i<64;i++) {
> +             *(str + i) = 'a';
> +     }
> +
> +     fd = open("/proc/xen/balloon", O_RDWR);
> +     if (fd == -1) {
> +             printf("%s FAIL: failed to open 
> /proc/xen/balloon, %s\n",
> +                     TESTNAME, strerror(errno));
> +             exit(1);
> +     }
> +     ret = write(fd, str, sizeof(str));
> +     err = errno;
> +     if (ret != -1) {
> +             printf("%s FAIL: Write 1 byte to 
> /proc/xen/balloon succeeded\n",
> +                     TESTNAME);
> +             close(fd);
> +             exit(1);
> +     }
> +     if (err != 27) {
> +             printf("%s FAIL: Write 1 byte got errno %d, 
> expected 27\n",
> +                     TESTNAME, err);
> +             close(fd);
> +             exit(1);
> +     }
> +     printf("%s PASS: Write 1 byte failed with -EFBIG as expected\n",
> +             TESTNAME);
> +     close(fd);
> +     exit(0);
> +}
> +
> diff -r b63577ff53a3 -r fa47e95d40dc tools/tests/balloon/memsteal.c
> --- /dev/null Fri Aug  5 14:57:43 2005
> +++ b/tools/tests/balloon/memsteal.c  Fri Aug  5 16:57:07 2005
> @@ -0,0 +1,52 @@
> +/*
> + *
> + * Copyright (c) International Business Machines  Corp., 2005
> + * This program is free software;  you can redistribute it and/or
> modify
> + * it under the terms of the GNU General Public License as 
> published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY;  without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
> + * the GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program;  if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 
> 02111-1307
> USA
> + *
> + * Test name: memsteal
> + * Author: Paul Larson <pl@xxxxxxxxxx>
> + * Description: simple memory allocator */
> +
> +#include <errno.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <unistd.h>
> +#include <sys/mman.h>
> +
> +int main(int argc, char **argv)
> +{
> +     int i;
> +     size_t memsize;
> +     char *chunk;
> +
> +     if (argc != 2) {
> +             printf("usage: memsteal [Memory in MB]\n"
> +                    "Allocates given amount of memory, 
> touches the pages,\n"
> +                    "and waits for a signal to exit.\n\n");
> +             exit(1);
> +     }
> +     memsize = atol(argv[1]) * 1024 * 1024;
> +     chunk = mmap(0, memsize, PROT_WRITE, 
> MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
> +     if (chunk == NULL) {
> +             perror("mmap()");
> +             exit(1);
> +     }
> +     for(i=0;i<memsize;i+=4096) {
> +             chunk[i]='a';
> +     }
> +     pause();
> +     exit(0);
> +}
> 
> 

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>