Scheduler working !

This commit is contained in:
Adrien Bourmault 2021-06-15 23:26:27 +02:00
parent 70bff11041
commit f98e51bf4a
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
11 changed files with 360 additions and 223 deletions

View File

@ -19,21 +19,22 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # # along with this program. If not, see <https://www.gnu.org/licenses/>. #
#=----------------------------------------------------------------------------=# #=----------------------------------------------------------------------------=#
CCOPTS=-pthread -Wall CCOPTS=-pthread -Wall -g -Os
LDFLAGS= -lc -lpthread LDFLAGS= -lc -lpthread
BINDIR=bin BINDIR=bin
SRCDIR=src SRCDIR=src
DEBDIR=debian DEBDIR=debian
OBJ=$(BINDIR)/scheduler.o $(BINDIR)/server.o $(BINDIR)/localworker.o $(BINDIR)/main.o OBJ= $(BINDIR)/scheduler.o $(BINDIR)/server.o $(BINDIR)/localworker.o \
$(BINDIR)/centers.o $(BINDIR)/main.o
.DEFAULT_GOAL:= all .DEFAULT_GOAL:= all
.PHONY: all clean deb tests install run .PHONY: all clean deb tests install run
# ---- Tests enumeration ----------------------------------------------------- # # ---- Tests enumeration ----------------------------------------------------- #
TEST_SCHEDULER=$(BINDIR)/tests/scheduler TEST_SCHEDULER=$(BINDIR)/tests/centers
TESTS=$(TEST_SCHEDULER) TESTS=$(TEST_SCHEDULER)
$(BINDIR)/tests/scheduler: $(SRCDIR)/tests/scheduler.c $(BINDIR)/tests/centers: $(SRCDIR)/tests/centers.c
@echo "Compiling $<" @echo "Compiling $<"
@$(CC) $(CCINCLUDES) $(CCOPTS) $(CCFLAGS) $(LDFLAGS) -o $@ $< @$(CC) $(CCINCLUDES) $(CCOPTS) $(CCFLAGS) $(LDFLAGS) -o $@ $<

View File

@ -62,7 +62,7 @@ struct {
int nmaxCycles; int nmaxCycles;
int ruleRadius; int ruleRadius;
pthread_t *id; pthread_t *id;
bool stopped; bool pleaseStop;
} typedef Scheduler_t; } typedef Scheduler_t;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -82,4 +82,7 @@ struct Center_t {
struct { struct {
pthread_t *id; pthread_t *id;
Center_t *localWorkAreaCenter; Center_t *localWorkAreaCenter;
bool pleaseStop;
bool terminated;
int returnValue;
} typedef Worker_t; } typedef Worker_t;

28
include/centers.h Normal file
View File

@ -0,0 +1,28 @@
//=-------------------------------------------------------------------------=//
// Local workers definition //
// //
// Copyright © 2021 The Gem-graph Project //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#ifndef BASE_H
#include "../include/base.h"
#endif
Center_t *CenterAdd(Center_t *anyCenter, Center_t *newCenter);
void CenterRemove(Center_t *oldCenter);

View File

@ -33,7 +33,14 @@ pthread_t *WorkerInit(Worker_t *worker);
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //
static inline void WorkerDestroy(Worker_t *worker) static inline void WorkerDestroy(Worker_t *worker)
{ {
worker->pleaseStop = false;
worker->terminated = false;
worker->returnValue = false;
free(worker->id); free(worker->id);
worker->id = NULL;
free(worker->localWorkAreaCenter);
worker->localWorkAreaCenter = NULL;
} }
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //

View File

@ -34,6 +34,11 @@ pthread_t *SchedInit(Scheduler_t *scheduler);
static inline void SchedDestroy(Scheduler_t *scheduler) static inline void SchedDestroy(Scheduler_t *scheduler)
{ {
free(scheduler->id); free(scheduler->id);
free(scheduler->globalDrawingSpace->space);
free(scheduler->globalDrawingSpace);
free(scheduler->arrowList->space);
free(scheduler->arrowList);
} }
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //

53
src/centers.c Normal file
View File

@ -0,0 +1,53 @@
//=-------------------------------------------------------------------------=//
// Centers management module //
// //
// Copyright © 2021 The Gem-graph Project //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../include/base.h"
/* -------------------------------------------------------------------------- */
Center_t *CenterAdd(Center_t *anyCenter, Center_t *newCenter)
{
if (!newCenter) return NULL;
if (anyCenter->next) {
anyCenter->next->prev = newCenter;
}
newCenter->next = anyCenter->next;
anyCenter->next = newCenter;
newCenter->prev = anyCenter;
return newCenter;
}
void CenterRemove(Center_t *oldCenter)
{
register Center_t *prev;
register Center_t *next;
printLog("Removing center %p\n", oldCenter);
if (!oldCenter) return;
prev = oldCenter->prev;
next = oldCenter->next;
if (prev) prev->next = oldCenter->next;
if (next) next->prev = oldCenter->prev;
}

View File

@ -31,7 +31,9 @@ static void *LittleWorker(void *worker);
pthread_t *WorkerInit(Worker_t *worker) pthread_t *WorkerInit(Worker_t *worker)
{ {
worker->id = (pthread_t*) malloc(sizeof(pthread_t)); worker->id = (pthread_t*) malloc(sizeof(pthread_t));
pthread_create(worker->id, NULL, LittleWorker, worker); if (pthread_create(worker->id, NULL, LittleWorker, worker)) {
printLog("Worker #%lu can't be initialized!\n", *(worker->id));
}
return worker->id; return worker->id;
} }
@ -40,8 +42,11 @@ pthread_t *WorkerInit(Worker_t *worker)
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //
static void *LittleWorker(void *worker) static void *LittleWorker(void *worker)
{ {
Worker_t *args = (Worker_t*) worker; Worker_t *args;
int a = 4; int a;
args = (Worker_t*) worker;
printLog("Worker #%lu online\n", *args->id);
for (int i = 0; i < 45000; i++) { for (int i = 0; i < 45000; i++) {
for (int j = i; j < 45000; j++) { for (int j = i; j < 45000; j++) {
@ -49,6 +54,10 @@ static void *LittleWorker(void *worker)
} }
} }
printf("thread %d\n", a); args->returnValue = 0;
args->terminated = true;
printLog("Worker #%lu offline\n", *args->id);
return NULL; return NULL;
} }

View File

@ -46,15 +46,15 @@ int main(int argc, char **argv)
// //
// Creating structure for the Scheduler // Creating structure for the Scheduler
// //
scheduler0 = (Scheduler_t*) malloc(sizeof(Scheduler_t)); scheduler0 = (Scheduler_t*) calloc(1, sizeof(Scheduler_t));
scheduler0->globalDrawingSpace = (IntArray_t*) malloc(sizeof(IntArray_t)); scheduler0->globalDrawingSpace = (IntArray_t*) calloc(1, sizeof(IntArray_t));
scheduler0->globalDrawingSpace->space = scheduler0->globalDrawingSpace->space =
(int*) malloc(sizeof(int)*SPACE_SIZE); (int*) calloc(SPACE_SIZE, sizeof(int));
scheduler0->globalDrawingSpace->size = SPACE_SIZE; scheduler0->globalDrawingSpace->size = SPACE_SIZE;
scheduler0->arrowList = (ArrowArray_t*) malloc(sizeof(ArrowArray_t)); scheduler0->arrowList = (ArrowArray_t*) calloc(1, sizeof(ArrowArray_t));
scheduler0->arrowList->space = (Arrow_t*) malloc(sizeof(Arrow_t)*ARROW_NUMBER); scheduler0->arrowList->space = (Arrow_t*) calloc(ARROW_NUMBER, sizeof(Arrow_t));
scheduler0->arrowList->size = ARROW_NUMBER; scheduler0->arrowList->size = ARROW_NUMBER;
scheduler0->nmaxThread = MAX_THREAD; scheduler0->nmaxThread = MAX_THREAD;
@ -69,12 +69,6 @@ int main(int argc, char **argv)
SchedDestroy(scheduler0); SchedDestroy(scheduler0);
free(scheduler0->globalDrawingSpace->space);
free(scheduler0->globalDrawingSpace);
free(scheduler0->arrowList->space);
free(scheduler0->arrowList);
free(scheduler0); free(scheduler0);
return 0; return 0;

View File

@ -20,6 +20,7 @@
//=-------------------------------------------------------------------------=// //=-------------------------------------------------------------------------=//
#include "../include/base.h" #include "../include/base.h"
#include "../include/centers.h"
#include "../include/localworker.h" #include "../include/localworker.h"
#include <sys/sysinfo.h> #include <sys/sysinfo.h>
@ -38,36 +39,6 @@ pthread_t *SchedInit(Scheduler_t *scheduler)
return scheduler->id; return scheduler->id;
} }
// -------------------------------------------------------------------------- //
// Center_t management functions //
// -------------------------------------------------------------------------- //
static inline void centerAssign(Center_t *center, int x, int y, int z)
{
center->x = x;
center->y = y;
center->z = z;
}
static inline Center_t *centerAdd(Center_t *anyCenter, Center_t *newCenter)
{
if (!newCenter) return NULL;
if (anyCenter->next) {
anyCenter->next->prev = newCenter;
}
newCenter->next = anyCenter->next;
anyCenter->next = newCenter;
newCenter->prev = anyCenter;
return newCenter;
}
static inline void centerRemove(Center_t *oldCenter)
{
if (!oldCenter) return;
if (oldCenter->prev) oldCenter->prev->next = oldCenter->next;
if (oldCenter->next) oldCenter->next->prev = oldCenter->prev;
}
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //
@ -76,7 +47,10 @@ static inline void centerRemove(Center_t *oldCenter)
static Center_t *findWorkArea(Center_t *centersList, Arrow_t *electedArrow, static Center_t *findWorkArea(Center_t *centersList, Arrow_t *electedArrow,
int ruleRadius, size_t spaceSize) int ruleRadius, size_t spaceSize)
{ {
register Center_t *currentCenter = centersList; register Center_t *currentCenter, *newCenter;
currentCenter = centersList;
newCenter = (Center_t*) malloc(sizeof(Center_t));
while (currentCenter){ while (currentCenter){
//printLog("Center : %d\n", currentCenter->x); //printLog("Center : %d\n", currentCenter->x);
@ -84,11 +58,15 @@ static Center_t *findWorkArea(Center_t *centersList, Arrow_t *electedArrow,
&& abs(electedArrow->y - currentCenter->y) >= ruleRadius && abs(electedArrow->y - currentCenter->y) >= ruleRadius
&& abs(electedArrow->z - currentCenter->z) >= ruleRadius && abs(electedArrow->z - currentCenter->z) >= ruleRadius
){ ){
return currentCenter; newCenter->x = electedArrow->x;
newCenter->y = electedArrow->y;
newCenter->z = electedArrow->z;
return newCenter;
} }
currentCenter = currentCenter->next; currentCenter = currentCenter->next;
} }
free(newCenter);
return NULL; return NULL;
} }
@ -103,13 +81,12 @@ static void *GreatScheduler(void *scheduler)
Worker_t *workerArray; Worker_t *workerArray;
Center_t *centersList, *workArea; Center_t *centersList, *workArea;
Arrow_t *electedArrow; Arrow_t *electedArrow;
long ncycles; int ncycles;
int ncpu, nworker; int ncpu, nworker;
// Getting scheduler argument structure // Getting scheduler argument structure
args = (Scheduler_t*) scheduler; args = (Scheduler_t*) scheduler;
printLog("Scheduler #%lu online\n", *(args->id)); printLog("Scheduler #%lu online\n", *args->id);
ncpu = get_nprocs(); ncpu = get_nprocs();
printLog("%d CPUs available.\n", ncpu); printLog("%d CPUs available.\n", ncpu);
@ -123,11 +100,12 @@ static void *GreatScheduler(void *scheduler)
// //
// MAIN LOOP // MAIN LOOP
// //
while (!args->stopped && ncycles <= args->nmaxCycles) { while (!args->pleaseStop && ncycles <= args->nmaxCycles) {
// Increment cycles // Increment cycles
ncycles++; ncycles++;
//printLog("Scheduler #%lu online: cycle %d\n", *args->id, ncycles);
// TODO statistics here // XXX statistics here
// Create a new thread // Create a new thread
if (nworker < ncpu) { if (nworker < ncpu) {
@ -141,37 +119,74 @@ static void *GreatScheduler(void *scheduler)
// If a free area exists, // If a free area exists,
if (workArea) { if (workArea) {
printLog("A free workArea exists at %p\n", workArea);
// preempt it, // preempt it,
centerAdd(centersList, workArea); CenterAdd(centersList, workArea);
// find a worker socket, // find a worker socket,
for (int i = 0; i < ncpu; i++) { for (int i = 0; i < ncpu; i++) {
if (!workerArray[i].id) { if (!workerArray[i].id) {
printLog("Adding worker at rank %d\n", i);
// prepare the worker for the area, // prepare the worker for the area,
workerArray[i].localWorkAreaCenter = workArea; workerArray[i].localWorkAreaCenter = workArea;
// create the worker, // create the worker,
WorkerInit(&workerArray[i]); WorkerInit(&workerArray[i]);
// and increment worker count. // and increment worker count.
nworker++; nworker++;
printLog("Added worker at rank %d with center %p, now %d worker(s)\n",
i,
workArea,
nworker
);
break; break;
} }
} }
} }
} }
// TODO Delete finished workers // Delete finished workers
for (int i = 0; i < ncpu; i++) { for (int i = 0; i < ncpu; i++) {
// XXX if (workerArray[i].id) {
//printLog("Checking termination of worker #%lu\n", *workerArray[i].id);
// Check worker termination
if (workerArray[i].terminated) {
// Join the thread to act his termination
WorkerWait(&workerArray[i]);
// Remove preemption on space
CenterRemove(workerArray[i].localWorkAreaCenter);
printLog("Worker #%lu terminated with return %d. Cleaning...\n",
*workerArray[i].id,
workerArray[i].returnValue
);
// Remove Worker
WorkerDestroy(&workerArray[i]);
nworker--;
}
}
} }
} }
// TODO Exiting scheduler properly // Exiting scheduler properly
// Waiting for remaining workers // Waiting for remaining workers
for (int i = 0; i < ncpu; i++) { for (int i = 0; i < ncpu; i++) {
// XXX if (workerArray[i].id) {
printLog("Waiting for termination of worker #%lu\n", *workerArray[i].id);
// Join the thread to wait for his termination
WorkerWait(&workerArray[i]);
// Remove preemption on space
CenterRemove(workerArray[i].localWorkAreaCenter);
printLog("Worker #%lu terminated with return %d. Cleaning...\n",
*workerArray[i].id,
workerArray[i].returnValue
);
// Remove Worker
WorkerDestroy(&workerArray[i]);
}
} }
printLog("Scheduler #%lu offline\n", *(args->id)); printLog("Scheduler #%lu offline\n", *args->id);
free(workerArray);
free(centersList);
return NULL; return NULL;
} }

181
src/tests/centers.c Normal file
View File

@ -0,0 +1,181 @@
//=-------------------------------------------------------------------------=//
// Centers tests //
// //
// Copyright © 2021 The Gem-graph Project //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../centers.c"
#include <assert.h>
//
// Tests for Center_t functions
//
void printCenters(Center_t *firstCenter)
{
while (firstCenter) {
printf("Center %p\n\tNext %p\n\tPrev %p\n\n",
firstCenter,
firstCenter->next,
firstCenter->prev
);
firstCenter = firstCenter->next;
}
}
bool TestCenterRemove
(void)
{
Center_t *anyCenter = NULL;
// adding a something to a bad pointer
centerRemove(anyCenter);
//printf("* Status of centers list after deleting NULL\n");
//printCenters(anyCenter);
assert(anyCenter == NULL);
anyCenter = (Center_t*) calloc(1, sizeof(Center_t));
//printf("* Initial status of centers list\n");
//printCenters(anyCenter);
assert(anyCenter->next == NULL);
assert(anyCenter->prev == NULL);
assert(anyCenter != NULL);
// Deleting a lonely pointer
centerRemove(anyCenter);
//printf("* Status of centers list after deleting a lonely center\n");
//printCenters(anyCenter);
anyCenter = (Center_t*) calloc(1, sizeof(Center_t));
centerAdd(anyCenter, (Center_t*) calloc(1, sizeof(Center_t)));
centerAdd(anyCenter, (Center_t*) calloc(1, sizeof(Center_t)));
centerAdd(anyCenter, (Center_t*) calloc(1, sizeof(Center_t)));
centerAdd(anyCenter, (Center_t*) calloc(1, sizeof(Center_t)));
centerAdd(anyCenter, (Center_t*) calloc(1, sizeof(Center_t)));
Center_t *oldfirst = anyCenter->next;
Center_t *oldsecond = anyCenter->next->next;
// Deleting a the first pointer
centerRemove(anyCenter->next);
//printf("* Status of centers list after deleting the head center\n");
//printCenters(anyCenter);
assert(anyCenter->next == oldsecond);
return true;
}
bool TestCenterAdd(void)
{
Center_t *anyCenter = NULL;
// adding a something to a bad pointer
centerAdd(anyCenter, NULL);
//printf("* Status of centers list after adding something to NULL\n");
//printCenters(anyCenter);
assert(anyCenter == NULL);
anyCenter = (Center_t*) calloc(1, sizeof(Center_t));
//printf("* Initial status of centers list\n");
//printCenters(anyCenter);
assert(anyCenter->next == NULL);
assert(anyCenter->prev == NULL);
assert(anyCenter != NULL);
// adding a bad pointer
centerAdd(anyCenter, NULL);
//printf("* Status of centers list after adding NULL\n");
//printCenters(anyCenter);
assert(anyCenter->next == NULL);
assert(anyCenter->prev == NULL);
assert(anyCenter != NULL);
// adding a good pointer
Center_t *goodpointer = (Center_t*) calloc(1, sizeof(Center_t));
centerAdd(anyCenter, goodpointer);
//printf("* Status of centers list after adding a center\n");
//printCenters(anyCenter);
assert(anyCenter != NULL);
assert(anyCenter->next == goodpointer);
assert(anyCenter->prev == NULL);
assert(goodpointer->prev == anyCenter);
assert(goodpointer->next == NULL);
// adding another good pointer
Center_t *newgoodpointer = (Center_t*) calloc(1, sizeof(Center_t));
centerAdd(anyCenter, newgoodpointer);
//printf("* Status of centers list after adding another center\n");
//printCenters(anyCenter);
assert(anyCenter != NULL);
assert(anyCenter->next == newgoodpointer);
assert(anyCenter->prev == NULL);
assert(newgoodpointer->prev == anyCenter);
assert(newgoodpointer->next == goodpointer);
// adding another good pointer
Center_t *strangepointer = (Center_t*) calloc(1, sizeof(Center_t));
strangepointer->next = (Center_t*)0xCAFEBABE;
strangepointer->prev = (Center_t*)0xCAFEBABE;
centerAdd(anyCenter, strangepointer);
//printf("* Status of centers list after adding a strange center\n");
//printCenters(anyCenter);
assert(anyCenter != NULL);
assert(anyCenter->next == strangepointer);
assert(anyCenter->prev == NULL);
assert(strangepointer->prev != (Center_t*)0xCAFEBABE);
assert(strangepointer->next != (Center_t*)0xCAFEBABE);
return true;
}
int main(int argc, char **argv)
{
printf("\n==== Testing centers.c/centerAdd() ====\n");
TestCenterAdd();
printf("\n==== Testing centers.c/centerAdd() ==== : OK\n");
printf("\n==== Testing centers.c/centerRemove() ====\n");
TestCenterRemove();
printf("\n==== Testing centers.c/centerRemove() ==== : OK\n");
return 0;
}

View File

@ -20,162 +20,3 @@
//=-------------------------------------------------------------------------=// //=-------------------------------------------------------------------------=//
#include "../scheduler.c" #include "../scheduler.c"
#include <assert.h>
//
// Tests for Center_t functions
//
void printCenters(Center_t *firstCenter)
{
while (firstCenter) {
printf("Center %p\n\tNext %p\n\tPrev %p\n\n",
firstCenter,
firstCenter->next,
firstCenter->prev
);
firstCenter = firstCenter->next;
}
}
bool TestCenterRemove
(void)
{
Center_t *anyCenter = NULL;
// adding a something to a bad pointer
centerRemove(anyCenter);
//printf("* Status of centers list after deleting NULL\n");
//printCenters(anyCenter);
assert(anyCenter == NULL);
anyCenter = (Center_t*) calloc(1, sizeof(Center_t));
//printf("* Initial status of centers list\n");
//printCenters(anyCenter);
assert(anyCenter->next == NULL);
assert(anyCenter->prev == NULL);
assert(anyCenter != NULL);
// Deleting a lonely pointer
centerRemove(anyCenter);
//printf("* Status of centers list after deleting a lonely center\n");
//printCenters(anyCenter);
anyCenter = (Center_t*) calloc(1, sizeof(Center_t));
centerAdd(anyCenter, (Center_t*) calloc(1, sizeof(Center_t)));
centerAdd(anyCenter, (Center_t*) calloc(1, sizeof(Center_t)));
centerAdd(anyCenter, (Center_t*) calloc(1, sizeof(Center_t)));
centerAdd(anyCenter, (Center_t*) calloc(1, sizeof(Center_t)));
centerAdd(anyCenter, (Center_t*) calloc(1, sizeof(Center_t)));
Center_t *oldfirst = anyCenter->next;
Center_t *oldsecond = anyCenter->next->next;
// Deleting a the first pointer
centerRemove(anyCenter->next);
//printf("* Status of centers list after deleting the head center\n");
//printCenters(anyCenter);
assert(anyCenter->next == oldsecond);
return true;
}
bool TestCenterAdd(void)
{
Center_t *anyCenter = NULL;
// adding a something to a bad pointer
centerAdd(anyCenter, NULL);
//printf("* Status of centers list after adding something to NULL\n");
//printCenters(anyCenter);
assert(anyCenter == NULL);
anyCenter = (Center_t*) calloc(1, sizeof(Center_t));
//printf("* Initial status of centers list\n");
//printCenters(anyCenter);
assert(anyCenter->next == NULL);
assert(anyCenter->prev == NULL);
assert(anyCenter != NULL);
// adding a bad pointer
centerAdd(anyCenter, NULL);
//printf("* Status of centers list after adding NULL\n");
//printCenters(anyCenter);
assert(anyCenter->next == NULL);
assert(anyCenter->prev == NULL);
assert(anyCenter != NULL);
// adding a good pointer
Center_t *goodpointer = (Center_t*) calloc(1, sizeof(Center_t));
centerAdd(anyCenter, goodpointer);
//printf("* Status of centers list after adding a center\n");
//printCenters(anyCenter);
assert(anyCenter != NULL);
assert(anyCenter->next == goodpointer);
assert(anyCenter->prev == NULL);
assert(goodpointer->prev == anyCenter);
assert(goodpointer->next == NULL);
// adding another good pointer
Center_t *newgoodpointer = (Center_t*) calloc(1, sizeof(Center_t));
centerAdd(anyCenter, newgoodpointer);
//printf("* Status of centers list after adding another center\n");
//printCenters(anyCenter);
assert(anyCenter != NULL);
assert(anyCenter->next == newgoodpointer);
assert(anyCenter->prev == NULL);
assert(newgoodpointer->prev == anyCenter);
assert(newgoodpointer->next == goodpointer);
// adding another good pointer
Center_t *strangepointer = (Center_t*) calloc(1, sizeof(Center_t));
strangepointer->next = (Center_t*)0xCAFEBABE;
strangepointer->prev = (Center_t*)0xCAFEBABE;
centerAdd(anyCenter, strangepointer);
//printf("* Status of centers list after adding a strange center\n");
//printCenters(anyCenter);
assert(anyCenter != NULL);
assert(anyCenter->next == strangepointer);
assert(anyCenter->prev == NULL);
assert(strangepointer->prev != (Center_t*)0xCAFEBABE);
assert(strangepointer->next != (Center_t*)0xCAFEBABE);
return true;
}
int main(int argc, char **argv)
{
printf("\n==== Testing scheduler.c/centerAdd() ====\n");
TestCenterAdd();
printf("\n==== Testing scheduler.c/centerAdd() ==== : OK\n");
printf("\n==== Testing scheduler.c/centerRemove() ====\n");
TestCenterRemove();
printf("\n==== Testing scheduler.c/centerRemove() ==== : OK\n");
return 0;
}