package semaphore;
import org.simgrid.msg.*;
-import org.simgrid.msg.Process;
-import org.simgrid.trace.Trace;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Random;
class SemCreator extends Process {
- Semaphore sem;
-
- SemCreator(Host h, String n){
- super(h, n);
- }
-
- public void main(String[] args) throws MsgException{
- int j;
- Msg.info("Creating 50 new Semaphores, yielding and triggering a GC after each");
- for(j = 1; j <= 50; j++) {
- sem = new Semaphore(0);
- waitFor(10);
- System.gc();
- }
- Msg.info("It worked, we survived. The test is passed.");
- }
+ Semaphore sem;
+
+ SemCreator(Host h, String n){
+ super(h, n);
+ }
+
+ public void main(String[] args) throws MsgException{
+ int j;
+ Msg.info("Creating 50 new Semaphores, yielding and triggering a GC after each");
+ for(j = 1; j <= 50; j++) {
+ sem = new Semaphore(0);
+ waitFor(10);
+ System.gc();
+ }
+ Msg.info("It worked, we survived. The test is passed.");
+ }
}
-
public class SemaphoreGC {
- public static void main(String[] args) throws Exception {
-
- Msg.init(args);
- if (args.length < 1) {
- Msg.info("Usage: java -cp simgrid.jar:. semaphore.SemaphoreGC <deployment.xml>");
- System.exit(1);
- }
- Msg.createEnvironment(args[0]);
-
- Host[] hosts = Host.all();
- new SemCreator(hosts[0], "SemCreator").start();
-
- Msg.run();
- }
-
+ public static void main(String[] args) throws Exception {
+ Msg.init(args);
+ if (args.length < 1) {
+ Msg.info("Usage: java -cp simgrid.jar:. semaphore.SemaphoreGC <deployment.xml>");
+ System.exit(1);
+ }
+ Msg.createEnvironment(args[0]);
+
+ Host[] hosts = Host.all();
+ new SemCreator(hosts[0], "SemCreator").start();
+
+ Msg.run();
+ }
}
package sleep_host_off;
import org.simgrid.msg.*;
-import org.simgrid.msg.Process;
-import org.simgrid.trace.Trace;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Random;
class Sleeper extends Process {
- public Sleeper(Host host, String name, String[] args) {
- super(host,name,args);
- }
- public void main(String[] args) {
- while (true) {
- Msg.info("I'm not dead");
- try {
- Process.sleep(10);
- } catch (HostFailureException e) {
- Msg.info("catch HostException: "+e.getLocalizedMessage());
- break; //Break is needed to finalize the endless loop
- }
- }
- }
+ public Sleeper(Host host, String name, String[] args) {
+ super(host,name,args);
+ }
+ public void main(String[] args) {
+ while (true) {
+ Msg.info("I'm not dead");
+ try {
+ Process.sleep(10);
+ } catch (HostFailureException e) {
+ Msg.info("catch HostException: "+e.getLocalizedMessage());
+ break; //Break is needed to finalize the endless loop
+ }
+ }
+ }
}
class TestRunner extends Process {
-
- public TestRunner(Host host, String name, String[] args) {
- super(host,name,args);
- }
-
- public void main(String[] strings) throws MsgException {
- Host host = Host.all()[1];
-
-
- Msg.info("**** **** **** ***** ***** Test Sleep ***** ***** **** **** ****");
- Msg.info("Test sleep: Create a process on "+host.getName()+" that simply make periodic sleep, turn off "+host.getName());
- new Sleeper(host, "Sleeper", null).start();
-
- waitFor(0.02);
- Msg.info("Stop "+host.getName());
- host.off();
- Msg.info(host.getName()+" has been stopped");
- waitFor(0.3);
- Msg.info("Test sleep seems ok, cool! (number of Process : " + Process.getCount() + ", it should be 1 (i.e. the Test one))");
- }
+ public TestRunner(Host host, String name, String[] args) {
+ super(host,name,args);
+ }
+
+ public void main(String[] strings) throws MsgException {
+ Host host = Host.all()[1];
+
+ Msg.info("**** **** **** ***** ***** Test Sleep ***** ***** **** **** ****");
+ Msg.info("Test sleep: Create a process on "+host.getName()+" that simply make periodic sleep, turn off "
+ +host.getName());
+ new Sleeper(host, "Sleeper", null).start();
+
+ waitFor(0.02);
+ Msg.info("Stop "+host.getName());
+ host.off();
+ Msg.info(host.getName()+" has been stopped");
+ waitFor(0.3);
+ Msg.info("Test sleep seems ok, cool! (number of Process : " + Process.getCount()
+ + ", it should be 1 (i.e. the Test one))");
+ }
}
public class SleepHostOff {
+ public static void main(String[] args) throws Exception {
+ Msg.init(args);
- public static void main(String[] args) throws Exception {
- /* Init. internal values */
- Msg.init(args);
-
- if (args.length < 1) {
- Msg.info("Usage: java -cp simgrid.jar:. sleep_host_off.SleepHostOff <platform.xml>");
- System.exit(1);
- }
+ if (args.length < 1) {
+ Msg.info("Usage: java -cp simgrid.jar:. sleep_host_off.SleepHostOff <platform.xml>");
+ System.exit(1);
+ }
- /* construct the platform and deploy the application */
- Msg.createEnvironment(args[0]);
+ Msg.createEnvironment(args[0]);
- Host[] hosts = Host.all();
- new TestRunner(hosts[0], "TestRunner", null).start();
+ Host[] hosts = Host.all();
+ new TestRunner(hosts[0], "TestRunner", null).start();
- Msg.run();
- }
+ Msg.run();
+ }
}
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
-#include <stdlib.h>
#include <stdio.h>
#include <xbt/xbt_os_time.h>
#define MAX_TEST 1000000
-int compare_double(const void *a, const void *b);
-
-void test_heap_validity(int size);
-void test_heap_mean_operation(int size);
-void test_reset_heap(xbt_heap_t * heap, int size);
-
-
-int compare_double(const void *a, const void *b)
+static int compare_double(const void *a, const void *b)
{
- double pa, pb;
-
- pa = *((double *) a);
- pb = *((double *) b);
+ double pa = *((double *) a);
+ double pb = *((double *) b);
if (pa > pb)
return 1;
return -1;
}
-void test_heap_validity(int size)
+static void test_heap_validity(int size)
{
xbt_heap_t heap = xbt_heap_new(size, NULL);
double *tab = xbt_new0(double, size);
-
int i;
for (i = 0; i < size; i++) {
printf("Validity test complete!\n");
}
-void test_heap_mean_operation(int size)
+static void test_heap_mean_operation(int size)
{
xbt_heap_t heap = xbt_heap_new(size, NULL);
- double val;
- double date = 0;
- int i, j;
- date = xbt_os_time() * 1000000;
- for (i = 0; i < size; i++)
+ double date = xbt_os_time() * 1000000;
+ for (int i = 0; i < size; i++)
xbt_heap_push(heap, NULL, (10.0 * rand() / (RAND_MAX + 1.0)));
date = xbt_os_time() * 1000000 - date;
printf("Creation time %d size heap : %g\n", size, date);
date = xbt_os_time() * 1000000;
- for (j = 0; j < MAX_TEST; j++) {
+ for (int j = 0; j < MAX_TEST; j++) {
if (!(j % size) && j)
test_reset_heap(&heap, size);
- val = xbt_heap_maxkey(heap);
+ double val = xbt_heap_maxkey(heap);
xbt_heap_pop(heap);
xbt_heap_push(heap, NULL, 3.0 * val);
}
date = xbt_os_time() * 1000000 - date;
- printf("Mean access time for a %d size heap : %g\n", size,
- date * 1.0 / (MAX_TEST + 0.0));
+ printf("Mean access time for a %d size heap : %g\n", size, date * 1.0 / (MAX_TEST + 0.0));
xbt_heap_free(heap);
}
-void test_reset_heap(xbt_heap_t * heap, int size)
+static void test_reset_heap(xbt_heap_t * heap, int size)
{
- int i;
xbt_heap_free(*heap);
*heap = xbt_heap_new(size, NULL);
- for (i = 0; i < size; i++) {
+ for (int i = 0; i < size; i++) {
xbt_heap_push(*heap, NULL, (10.0 * rand() / (RAND_MAX + 1.0)));
}
-
}
int main(int argc, char **argv)
XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Logs of this example");
-
int main(int argc, char *argv[])
{
char *tmp = bprintf("\n%d%s%d%s%d%s%d%s%d%s%d%s%d%s%d%s%d%s%d%s",
- 1,
- ".........1.........2.........3.........4.........5.........6.........7.........8.........9.........0\n",
- 2,
- ".........1.........2.........3.........4.........5.........6.........7.........8.........9.........0\n",
- 3,
- ".........1.........2.........3.........4.........5.........6.........7.........8.........9.........0\n",
- 4,
- ".........1.........2.........3.........4.........5.........6.........7.........8.........9.........0\n",
- 5,
- ".........1.........2.........3.........4.........5.........6.........7.........8.........9.........0\n",
- 6,
- ".........1.........2.........3.........4.........5.........6.........7.........8.........9.........0\n",
- 7,
- ".........1.........2.........3.........4.........5.........6.........7.........8.........9.........0\n",
- 8,
- ".........1.........2.........3.........4.........5.........6.........7.........8.........9.........0\n",
- 9,
- ".........1.........2.........3.........4.........5.........6.........7.........8.........9.........0\n",
- 0,
- ".........1.........2.........3.........4.........5.........6.........7.........8.........9.........0\n");
+ 1, ".........1.........2.........3.........4.........5.........6.........7.........8.........9.........0\n",
+ 2, ".........1.........2.........3.........4.........5.........6.........7.........8.........9.........0\n",
+ 3, ".........1.........2.........3.........4.........5.........6.........7.........8.........9.........0\n",
+ 4, ".........1.........2.........3.........4.........5.........6.........7.........8.........9.........0\n",
+ 5, ".........1.........2.........3.........4.........5.........6.........7.........8.........9.........0\n",
+ 6, ".........1.........2.........3.........4.........5.........6.........7.........8.........9.........0\n",
+ 7, ".........1.........2.........3.........4.........5.........6.........7.........8.........9.........0\n",
+ 8, ".........1.........2.........3.........4.........5.........6.........7.........8.........9.........0\n",
+ 9, ".........1.........2.........3.........4.........5.........6.........7.........8.........9.........0\n",
+ 0, ".........1.........2.........3.........4.........5.........6.........7.........8.........9.........0\n");
xbt_init(&argc, argv);
#include "xbt.h"
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(test, top,
- "Logging specific to this test");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(test, top, "Logging specific to this test");
XBT_LOG_NEW_CATEGORY(top, "Useless test channel");
static void dolog(const char *settings)
XBT_CRITICAL("false alarm%s%s%s%s%s%s", "", "", "", "", "", "!");
}
-
int main(int argc, char **argv)
{
xbt_init(&argc, argv);
{
xbt_mallocator_initialization_is_done(1);
int i = 0;
- xbt_mallocator_t mallocator = xbt_mallocator_new(65536,
- element_mallocator_new_f,
- element_mallocator_free_f,
- element_mallocator_reset_f);
+ xbt_mallocator_t mallocator =
+ xbt_mallocator_new(65536, element_mallocator_new_f, element_mallocator_free_f, element_mallocator_reset_f);
xbt_dynar_t elems = xbt_dynar_new(sizeof(element_t), NULL);
element_t elem = NULL;
base_mallocator = xbt_mallocator_get(mallocator);
xbt_die("FAIL: A double-free went undetected (for size:%d)",size_of_block(i));
}
-
XBT_INFO("Damnit, I cannot break mmalloc this time. That's SO disappointing.");
return 0;
}
XBT_LOG_NEW_DEFAULT_CATEGORY(synchro_crashtest, "Logs of this example");
-
int test_amount = 99; /* Up to 999 to not break the logs (and thus the testing mecanism) */
int crasher_amount = 99; /* Up to 99 to not break the logs (and thus the testing mecanism) */
int *id; /* to pass a pointer to the threads without race condition */
static void* crasher_thread(void *arg)
{
int id = *(int *) arg;
- int i;
- for (i = 0; i < test_amount; i++) {
+ for (int i = 0; i < test_amount; i++) {
if (more_info)
XBT_INFO("%03d (%02d|%02d|%02d|%02d|%02d|%02d|%02d|%02d|%02d)",
test_amount - i, id, id, id, id, id, id, id, id, id);
/* spawn threads */
for (i = 0; i < crasher_amount; i++) {
char *name = bprintf("thread %d", i);
- crashers[i] =
- xbt_os_thread_create(name, &crasher_thread, &id[i], NULL );
+ crashers[i] = xbt_os_thread_create(name, &crasher_thread, &id[i], NULL );
free(name);
}
i++;
} while (elapsed_time < TIMEOUT);
- printf("ran %d times in %g seconds (%g/s)\n",
- i, elapsed_time, i / elapsed_time);
+ printf("ran %d times in %g seconds (%g/s)\n", i, elapsed_time, i / elapsed_time);
xbt_dynar_free(&data);
xbt_free(a);
{
unsigned *a;
xbt_dynar_t data;
- xbt_parmap_t parmap;
- int i;
double start_time, elapsed_time;
printf("** mode = %-15s ", parmap_mode_name(mode));
array_new(&a, &data);
- parmap = xbt_parmap_new(nthreads, mode);
- i = 0;
+ xbt_parmap_t parmap = xbt_parmap_new(nthreads, mode);
+ int i = 0;
start_time = xbt_os_time();
do {
xbt_parmap_apply(parmap, fun_to_apply, data);
static void bench_all_modes(void (*bench_fun)(int, e_xbt_parmap_mode_t),
int nthreads, unsigned modes)
{
- e_xbt_parmap_mode_t all_modes[] = {
- XBT_PARMAP_POSIX, XBT_PARMAP_FUTEX,
- XBT_PARMAP_BUSY_WAIT, XBT_PARMAP_DEFAULT
- };
- unsigned i;
- for (i = 0 ; i < sizeof all_modes / sizeof all_modes[0] ; i++) {
+ e_xbt_parmap_mode_t all_modes[] = {XBT_PARMAP_POSIX, XBT_PARMAP_FUTEX, XBT_PARMAP_BUSY_WAIT, XBT_PARMAP_DEFAULT};
+
+ for (unsigned i = 0 ; i < sizeof all_modes / sizeof all_modes[0] ; i++) {
if (1U << i & modes)
bench_fun(nthreads, all_modes[i]);
}
SIMIX_global_init(&argc, argv);
if (argc != 2 && argc != 3) {
- fprintf(stderr,
- "Usage: %s nthreads [modes]\n"
+ fprintf(stderr, "Usage: %s nthreads [modes]\n"
" nthreads - number of working threads\n"
" modes - bitmask of modes to test\n",
argv[0]);
if (argc == 3)
modes = strtol(argv[2], NULL, 0);
- printf("Parmap benchmark with %d workers (modes = %#x)...\n\n",
- nthreads, modes);
+ printf("Parmap benchmark with %d workers (modes = %#x)...\n\n", nthreads, modes);
fun_to_apply = fun_small_comp;
for (i = 0; i < len; i++) {
unsigned expected = (1U << num) * (i + 1) - 1;
if (a[i] != expected) {
- XBT_CRITICAL("with %u threads, a[%u]: expected %u, got %u",
- num_workers, i, expected, a[i]);
+ XBT_CRITICAL("with %u threads, a[%u]: expected %u, got %u", num_workers, i, expected, a[i]);
ret = 1;
break;
}