Fix coding style issues.

Some checkpatch issues were solved by scripts leaving other problems
such as alignment and indentation issues.  In order to comply with the
defined coding style the following fixes were made:

- Fixed the function declaration moving the parameters' comments above
  the function in accordance to the doxygen format.
- Fixed functions' opening and closing brackets. These brackets should
  not be indented.
- Fixed the 'if', 'for' and 'while' statements adding the brackets
  around the sentence.
- Fixed comments' alignment.
- Fixed indentation.

The work was done manually and submitted as one commit. I didn't
separate these changes in different commits because they were fixed all
at once. Basically, all errors were fixed in every file at once.

Change-Id: Icc94a10bfd2cff82007ce60df23b2ccd4c30268d
Signed-off-by: Yonattan Louise <yonattan.a.louise.mendoza@intel.com>
This commit is contained in:
Yonattan Louise 2015-05-14 16:30:48 -05:00 committed by Anas Nashif
commit dbada63eee
95 changed files with 4179 additions and 4030 deletions

View file

@ -119,8 +119,7 @@ void irq_handler_set(unsigned int vector,
/* does the encoded offset match <oldRoutine> ? */ /* does the encoded offset match <oldRoutine> ? */
if (opcodeOff == opcodeOffToMatch) { if (opcodeOff == opcodeOffToMatch) {
/* match found -> write new routine and parameter */ /* match found -> write new routine and parameter */
UNALIGNED_WRITE( UNALIGNED_WRITE(
(unsigned int *)&pIntStubMem[ix + 1], (unsigned int *)&pIntStubMem[ix + 1],

View file

@ -58,14 +58,16 @@ This module implements the PCI config space access functions
* *
* pci_config_out_long - write a 32bit data to pci reg in offset * pci_config_out_long - write a 32bit data to pci reg in offset
* *
* @param bus_no Bus number.
* @param device_no Device number
* @param func_no Function number
* @param offset Offset into the configuration space.
* @param data Data written to the offset.
*
* RETURNS: N/A * RETURNS: N/A
*/ */
void pci_config_out_long(uint32_t bus_no, /* bus number */ void pci_config_out_long(uint32_t bus_no, uint32_t device_no, uint32_t func_no,
uint32_t device_no, /* device number */ uint32_t offset, uint32_t data)
uint32_t func_no, /* function number */
uint32_t offset, /* offset into the configuration space */
uint32_t data /* data written to the offset */
)
{ {
union pci_addr_reg pci_addr; union pci_addr_reg pci_addr;
@ -86,14 +88,16 @@ void pci_config_out_long(uint32_t bus_no, /* bus number */
* *
* pci_config_out_word - write a 16bit data to pci reg in offset * pci_config_out_word - write a 16bit data to pci reg in offset
* *
* @param bus_no Bus number.
* @param device_no Device number.
* @param func_no Function number.
* @param offset Offset into the configuration space.
* @param data Data written to the offset.
*
* RETURNS: N/A * RETURNS: N/A
*/ */
void pci_config_out_word(uint32_t bus_no, /* bus number */ void pci_config_out_word(uint32_t bus_no, uint32_t device_no, uint32_t func_no,
uint32_t device_no, /* device number */ uint32_t offset, uint16_t data)
uint32_t func_no, /* function number */
uint32_t offset, /* offset into the configuration space */
uint16_t data /* data written to the offset */
)
{ {
union pci_addr_reg pci_addr; union pci_addr_reg pci_addr;
@ -114,14 +118,16 @@ void pci_config_out_word(uint32_t bus_no, /* bus number */
* *
* pci_config_out_byte - write a 8bit data to pci reg in offset * pci_config_out_byte - write a 8bit data to pci reg in offset
* *
* @param bus_no Bus number.
* @param device_no Device number.
* @param func_no Function number.
* @param offset Offset into the configuration space.
* @param data Data written to the offset.
*
* RETURNS: N/A * RETURNS: N/A
*/ */
void pci_config_out_byte(uint32_t bus_no, /* bus number */ void pci_config_out_byte(uint32_t bus_no, uint32_t device_no, uint32_t func_no,
uint32_t device_no, /* device number */ uint32_t offset, uint8_t data)
uint32_t func_no, /* function number */
uint32_t offset, /* offset into the configuration space */
uint8_t data /* data written to the offset */
)
{ {
union pci_addr_reg pci_addr; union pci_addr_reg pci_addr;
@ -142,15 +148,17 @@ void pci_config_out_byte(uint32_t bus_no, /* bus number */
* *
* pci_config_in_long - read a 32bit data from pci reg in offset * pci_config_in_long - read a 32bit data from pci reg in offset
* *
* @param bus_no Bus number.
* @param device_no Device number.
* @param func_no Function number.
* @param offset Offset into the configuration space.
* @param data Data read from the offset.
*
* RETURNS: N/A * RETURNS: N/A
* *
*/ */
void pci_config_in_long(uint32_t bus_no, /* bus number */ void pci_config_in_long(uint32_t bus_no, uint32_t device_no, uint32_t func_no,
uint32_t device_no, /* device number */ uint32_t offset, uint32_t *data)
uint32_t func_no, /* function number */
uint32_t offset, /* offset into the configuration space */
uint32_t *data /* data read from the offset */
)
{ {
union pci_addr_reg pci_addr; union pci_addr_reg pci_addr;
@ -171,16 +179,18 @@ void pci_config_in_long(uint32_t bus_no, /* bus number */
* *
* pci_config_in_word - read in a 16bit data from a pci reg in offset * pci_config_in_word - read in a 16bit data from a pci reg in offset
* *
* @param bus_no Bus number.
* @param device_no Device number.
* @param func_no Function number.
* @param offset Offset into the configuration space.
* @param data Data read from the offset.
*
* RETURNS: N/A * RETURNS: N/A
* *
*/ */
void pci_config_in_word(uint32_t bus_no, /* bus number */ void pci_config_in_word(uint32_t bus_no, uint32_t device_no, uint32_t func_no,
uint32_t device_no, /* device number */ uint32_t offset, uint16_t *data)
uint32_t func_no, /* function number */
uint32_t offset, /* offset into the configuration space */
uint16_t *data /* data read from the offset */
)
{ {
union pci_addr_reg pci_addr; union pci_addr_reg pci_addr;
uint32_t pci_data; uint32_t pci_data;
@ -206,16 +216,18 @@ void pci_config_in_word(uint32_t bus_no, /* bus number */
* *
* pci_config_in_byte - read in a 8bit data from a pci reg in offset * pci_config_in_byte - read in a 8bit data from a pci reg in offset
* *
* @param bus_no Bus number.
* @param device_no Device number.
* @param func_no Function number.
* @param offset Offset into the configuration space.
* @param data Data read from the offset.
*
* RETURNS: N/A * RETURNS: N/A
* *
*/ */
void pci_config_in_byte(uint32_t bus_no, /* bus number */ void pci_config_in_byte(uint32_t bus_no, uint32_t device_no, uint32_t func_no,
uint32_t device_no, /* device number */ uint32_t offset, uint8_t *data)
uint32_t func_no, /* function number */
uint32_t offset, /* offset into the configuration space */
uint8_t *data /* data read from the offset */
)
{ {
union pci_addr_reg pci_addr; union pci_addr_reg pci_addr;
uint32_t pci_data; uint32_t pci_data;
@ -245,17 +257,19 @@ void pci_config_in_byte(uint32_t bus_no, /* bus number */
* capabilities in config space. If found, the offset of the first byte * capabilities in config space. If found, the offset of the first byte
* of the capability of interest in config space is returned via pOffset. * of the capability of interest in config space is returned via pOffset.
* *
* @param ext_cap_find_id Extended capabilities ID to search for.
* @param bus PCI bus number.
* @param device PCI device number.
* @param function PCI function number.
* @param p_offset Returned config space offset.
*
* RETURNS: 0 if Extended Capability found, -1 otherwise * RETURNS: 0 if Extended Capability found, -1 otherwise
* *
*/ */
int pci_config_ext_cap_ptr_find( int pci_config_ext_cap_ptr_find(uint8_t ext_cap_find_id, uint32_t bus,
uint8_t ext_cap_find_id, /* Extended capabilities ID to search for */ uint32_t device, uint32_t function,
uint32_t bus, /* PCI bus number */ uint8_t *p_offset)
uint32_t device, /* PCI device number */
uint32_t function, /* PCI function number */
uint8_t *p_offset /* returned config space offset */
)
{ {
uint16_t tmp_stat; uint16_t tmp_stat;
uint8_t tmp_offset; uint8_t tmp_offset;
@ -266,8 +280,9 @@ int pci_config_ext_cap_ptr_find(
pci_config_in_word(bus, device, function, PCI_CFG_STATUS, &tmp_stat); pci_config_in_word(bus, device, function, PCI_CFG_STATUS, &tmp_stat);
if ((tmp_stat & PCI_STATUS_NEW_CAP) == 0) if ((tmp_stat & PCI_STATUS_NEW_CAP) == 0) {
return -1; return -1;
}
/* Get the initial ECP offset and make longword aligned */ /* Get the initial ECP offset and make longword aligned */
@ -276,8 +291,9 @@ int pci_config_ext_cap_ptr_find(
/* Bounds check the ECP offset */ /* Bounds check the ECP offset */
if (cap_offset < 0x40) if (cap_offset < 0x40) {
return -1; return -1;
}
/* Look for the specified Extended Cap item in the linked list */ /* Look for the specified Extended Cap item in the linked list */
@ -294,8 +310,7 @@ int pci_config_ext_cap_ptr_find(
/* Get the offset to the next New Capabilities item */ /* Get the offset to the next New Capabilities item */
tmp_offset = cap_offset + (uint8_t)0x01; tmp_offset = cap_offset + (uint8_t)0x01;
pci_config_in_byte( pci_config_in_byte(bus, device, function, (int)tmp_offset, &cap_offset);
bus, device, function, (int)tmp_offset, &cap_offset);
} }
return -1; return -1;

View file

@ -33,23 +33,24 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
void usage( /*
char *progname /* name of the program to use */ *
) * @param progname Name of the program to use.
{ *
*/
void usage(char *progname)
{
fprintf(stderr, "Utility converts decimal numbers to hexadecimal\n"); fprintf(stderr, "Utility converts decimal numbers to hexadecimal\n");
fprintf(stderr, "Usage: %s <decimal number>\n", progname); fprintf(stderr, "Usage: %s <decimal number>\n", progname);
} }
int main( int main(int argc, char *argv[])
int argc, {
char *argv[]
)
{
if (argc != 2) { if (argc != 2) {
usage(argv[0]); usage(argv[0]);
return -1; return -1;
} }
printf("%X\n", atoi(argv[1])); printf("%X\n", atoi(argv[1]));
return 0; return 0;
} }

View file

@ -85,7 +85,7 @@ static void clean_exit(const int exit_code);
typedef struct s_isrList { typedef struct s_isrList {
void *fnc; void *fnc;
unsigned int dpl; unsigned int dpl;
} ISR_LIST; } ISR_LIST;
static ISR_LIST idt[256]; static ISR_LIST idt[256];
@ -95,7 +95,7 @@ enum {
NUSERFILES, /* number of user-provided file names */ NUSERFILES, /* number of user-provided file names */
EXECFILE=NUSERFILES, /* for name of executable */ EXECFILE=NUSERFILES, /* for name of executable */
NFILES /* total number of files open */ NFILES /* total number of files open */
}; };
enum { SHORT_USAGE, LONG_USAGE }; enum { SHORT_USAGE, LONG_USAGE };
static int fds[NUSERFILES] = {-1, -1}; static int fds[NUSERFILES] = {-1, -1};
@ -104,105 +104,105 @@ static unsigned int numVecs = (unsigned int)-1;
static struct version version = {KERNEL_VERSION, 1, 1, 0}; static struct version version = {KERNEL_VERSION, 1, 1, 0};
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
get_exec_name(argv[0]); get_exec_name(argv[0]);
get_options(argc, argv); /* may exit */ get_options(argc, argv); /* may exit */
open_files(); /* may exit */ open_files(); /* may exit */
genIdt(); genIdt();
close_files(); close_files();
return 0; return 0;
} }
static void get_options(int argc, char *argv[]) static void get_options(int argc, char *argv[])
{ {
char *endptr; char *endptr;
int ii, opt; int ii, opt;
while ((opt = getopt(argc, argv, "hi:o:n:v")) != -1) { while ((opt = getopt(argc, argv, "hi:o:n:v")) != -1) {
switch(opt) { switch(opt) {
case 'i': case 'i':
filenames[IFILE] = optarg; filenames[IFILE] = optarg;
break; break;
case 'o': case 'o':
{ {
filenames[OFILE] = optarg; filenames[OFILE] = optarg;
break; break;
} }
case 'h': case 'h':
usage(LONG_USAGE); usage(LONG_USAGE);
exit(0); exit(0);
case 'n': case 'n':
numVecs = (unsigned int)strtoul(optarg, &endptr, 10); numVecs = (unsigned int)strtoul(optarg, &endptr, 10);
if (*optarg == '\0' || *endptr != '\0') { if (*optarg == '\0' || *endptr != '\0') {
usage(SHORT_USAGE); usage(SHORT_USAGE);
exit(-1); exit(-1);
} }
break; break;
case 'v': case 'v':
show_version(filenames[EXECFILE], &version); show_version(filenames[EXECFILE], &version);
exit(0); exit(0);
default: default:
usage(SHORT_USAGE); usage(SHORT_USAGE);
exit(-1); exit(-1);
} }
} }
if ((unsigned int)-1 == numVecs) { if ((unsigned int)-1 == numVecs) {
usage(SHORT_USAGE); usage(SHORT_USAGE);
exit(-1); exit(-1);
} }
for(ii = IFILE; ii < NUSERFILES; ii++) { for(ii = IFILE; ii < NUSERFILES; ii++) {
if (!filenames[ii]) { if (!filenames[ii]) {
usage(SHORT_USAGE); usage(SHORT_USAGE);
exit(-1); exit(-1);
} }
}
} }
}
static void get_exec_name(char *pathname) static void get_exec_name(char *pathname)
{ {
int end = strlen(pathname)-1; int end = strlen(pathname)-1;
while(end != -1) { while(end != -1) {
#if defined(WINDOWS) /* Might have both slashes in path */ #if defined(WINDOWS) /* Might have both slashes in path */
if (pathname[end] == '/' || pathname[end] == '\\') if (pathname[end] == '/' || pathname[end] == '\\')
#else #else
if (pathname[end] == '/') if (pathname[end] == '/')
#endif #endif
{ {
if (0 == end || pathname[end-1] != '\\') { if (0 == end || pathname[end-1] != '\\') {
++end; ++end;
break; break;
}
} }
} --end;
--end;
} }
filenames[EXECFILE] = &pathname[end]; filenames[EXECFILE] = &pathname[end];
} }
static void open_files(void) static void open_files(void)
{ {
int ii; int ii;
fds[IFILE] = open(filenames[IFILE], O_RDONLY|O_BINARY); fds[IFILE] = open(filenames[IFILE], O_RDONLY|O_BINARY);
fds[OFILE] = open(filenames[OFILE], O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, fds[OFILE] = open(filenames[OFILE], O_WRONLY|O_CREAT|O_TRUNC|O_BINARY,
S_IWUSR|S_IRUSR); S_IWUSR|S_IRUSR);
for(ii = 0; ii < NUSERFILES; ii++) { for(ii = 0; ii < NUSERFILES; ii++) {
int invalid = fds[ii] == -1; int invalid = fds[ii] == -1;
if (invalid) { if (invalid) {
char *invalid = filenames[ii]; char *invalid = filenames[ii];
fprintf(stderr, "invalid file %s\n", invalid); fprintf(stderr, "invalid file %s\n", invalid);
for(--ii; ii >= 0; ii--) { for(--ii; ii >= 0; ii--) {
close(fds[ii]); close(fds[ii]);
}
exit(-1);
} }
exit(-1);
}
}
} }
}
static void genIdt(void) static void genIdt(void)
{ {
unsigned int i; unsigned int i;
unsigned int size; unsigned int size;
void *spurAddr; void *spurAddr;
@ -212,21 +212,25 @@ static void genIdt(void)
* First find the address of the spurious interrupt handlers. They are the * First find the address of the spurious interrupt handlers. They are the
* contained in the first 8 bytes of the input file. * contained in the first 8 bytes of the input file.
*/ */
if (read(fds[IFILE], &spurAddr, 4) < 4) if (read(fds[IFILE], &spurAddr, 4) < 4) {
goto readError; goto readError;
}
if (read(fds[IFILE], &spurNoErrAddr, 4) < 4) if (read(fds[IFILE], &spurNoErrAddr, 4) < 4) {
goto readError; goto readError;
}
PRINTF("Spurious int handlers found at %p and %p\n", PRINTF("Spurious int handlers found at %p and %p\n",
spurAddr, spurNoErrAddr); spurAddr, spurNoErrAddr);
/* Initially fill in the IDT array with the spurious handlers */ /* Initially fill in the IDT array with the spurious handlers */
for (i = 0; i < numVecs; i++) { for (i = 0; i < numVecs; i++) {
if ((((1 << i) & _EXC_ERROR_CODE_FAULTS)) && (i < 32)) if ((((1 << i) & _EXC_ERROR_CODE_FAULTS)) && (i < 32)) {
idt[i].fnc = spurAddr; idt[i].fnc = spurAddr;
else }
idt[i].fnc = spurNoErrAddr; else {
idt[i].fnc = spurNoErrAddr;
}
} }
/* /*
@ -234,35 +238,39 @@ static void genIdt(void)
* entries is the next 4 bytes * entries is the next 4 bytes
*/ */
if (read(fds[IFILE], &size, 4) < 4) if (read(fds[IFILE], &size, 4) < 4) {
goto readError; goto readError;
}
PRINTF("There are %d ISR(s)\n", size); PRINTF("There are %d ISR(s)\n", size);
if (size > numVecs) { if (size > numVecs) {
fprintf(stderr, "Too many ISRs found. Got %u. Expected less than %u." fprintf(stderr, "Too many ISRs found. Got %u. Expected less than %u."
" Malformed input file?\n", size, numVecs); " Malformed input file?\n", size, numVecs);
clean_exit(-1); clean_exit(-1);
} }
while (size--) { while (size--) {
void *addr; void *addr;
unsigned int vec; unsigned int vec;
unsigned int dpl; unsigned int dpl;
/* Get address */ /* Get address */
if (read(fds[IFILE], &addr, 4) < 4) if (read(fds[IFILE], &addr, 4) < 4) {
goto readError; goto readError;
/* Get vector */ }
if (read(fds[IFILE], &vec, 4) < 4) /* Get vector */
goto readError; if (read(fds[IFILE], &vec, 4) < 4) {
/* Get dpl */ goto readError;
if (read(fds[IFILE], &dpl, 4) < 4) }
goto readError; /* Get dpl */
if (read(fds[IFILE], &dpl, 4) < 4) {
goto readError;
}
PRINTF("ISR @ %p on Vector %d: dpl %d\n", addr, vec, dpl); PRINTF("ISR @ %p on Vector %d: dpl %d\n", addr, vec, dpl);
idt[vec].fnc = addr; idt[vec].fnc = addr;
idt[vec].dpl = dpl; idt[vec].dpl = dpl;
} }
/* /*
@ -271,11 +279,11 @@ static void genIdt(void)
*/ */
for (i = 0; i < numVecs; i++) { for (i = 0; i < numVecs; i++) {
unsigned long long idtEnt; unsigned long long idtEnt;
_IdtEntCreate(&idtEnt, idt[i].fnc, idt[i].dpl); _IdtEntCreate(&idtEnt, idt[i].fnc, idt[i].dpl);
write(fds[OFILE], &idtEnt, 8); write(fds[OFILE], &idtEnt, 8);
} }
return; return;
@ -283,31 +291,29 @@ static void genIdt(void)
readError: readError:
fprintf(stderr, "Error occured while reading input file. Aborting...\n"); fprintf(stderr, "Error occured while reading input file. Aborting...\n");
clean_exit(-1); clean_exit(-1);
} }
static void close_files(void) static void close_files(void)
{ {
int ii; int ii;
for(ii = 0; ii < NUSERFILES; ii++) { for(ii = 0; ii < NUSERFILES; ii++) {
close(fds[ii]); close(fds[ii]);
}
} }
}
static void clean_exit(const int exit_code) static void clean_exit(const int exit_code)
{ {
close_files(); close_files();
exit(exit_code); exit(exit_code);
} }
static void usage(const int len) static void usage(const int len)
{ {
fprintf(stderr, fprintf(stderr, "\n%s -i <input file> -n <n>\n", filenames[EXECFILE]);
"\n%s -i <input file> -n <n>\n",
filenames[EXECFILE]);
if (len == SHORT_USAGE) { if (len == SHORT_USAGE) {
return; return;
} }
fprintf(stderr, fprintf(stderr,
@ -323,4 +329,4 @@ static void usage(const int len)
" -v Display version.\n\n" " -v Display version.\n\n"
" -h Display this help.\n\n" " -h Display this help.\n\n"
"\nReturns -1 on error, 0 on success\n\n"); "\nReturns -1 on error, 0 on success\n\n");
} }

View file

@ -71,7 +71,7 @@ typedef struct {
Elf32_Half e_shentsize; Elf32_Half e_shentsize;
Elf32_Half e_shnum; Elf32_Half e_shnum;
Elf32_Half e_shstrndx; Elf32_Half e_shstrndx;
} Elf32_Ehdr; } Elf32_Ehdr;
#define EHDRSZ sizeof(Elf32_Ehdr) #define EHDRSZ sizeof(Elf32_Ehdr)
@ -245,7 +245,7 @@ typedef struct {
unsigned char st_info; unsigned char st_info;
unsigned char st_other; unsigned char st_other;
Elf32_Half st_shndx; Elf32_Half st_shndx;
} Elf32_Sym; } Elf32_Sym;
#define STN_UNDEF 0 #define STN_UNDEF 0
@ -289,13 +289,13 @@ typedef struct {
typedef struct { typedef struct {
Elf32_Addr r_offset; Elf32_Addr r_offset;
Elf32_Word r_info; Elf32_Word r_info;
} Elf32_Rel; } Elf32_Rel;
typedef struct { typedef struct {
Elf32_Addr r_offset; Elf32_Addr r_offset;
Elf32_Word r_info; Elf32_Word r_info;
Elf32_Sword r_addend; Elf32_Sword r_addend;
} Elf32_Rela; } Elf32_Rela;
#define ELF32_R_SYM(info) ((info)>>8) #define ELF32_R_SYM(info) ((info)>>8)
#define ELF32_R_TYPE(info) ((unsigned char)(info)) #define ELF32_R_TYPE(info) ((unsigned char)(info))
@ -313,7 +313,7 @@ typedef struct {
Elf32_Word p_memsz; Elf32_Word p_memsz;
Elf32_Word p_flags; Elf32_Word p_flags;
Elf32_Word p_align; Elf32_Word p_align;
} Elf32_Phdr; } Elf32_Phdr;
#define PHDRSZ sizeof(Elf32_Phdr) #define PHDRSZ sizeof(Elf32_Phdr)
@ -341,10 +341,10 @@ typedef struct {
typedef struct { typedef struct {
Elf32_Sword d_tag; Elf32_Sword d_tag;
union { union {
Elf32_Word d_val; Elf32_Word d_val;
Elf32_Addr d_ptr; Elf32_Addr d_ptr;
} d_un; } d_un;
} Elf32_Dyn; } Elf32_Dyn;
#define DT_NULL 0 #define DT_NULL 0
#define DT_NEEDED 1 #define DT_NEEDED 1

View file

@ -198,8 +198,8 @@ static Elf32_Shdr *shdr; /* pointer to array ELF section headers */
static void swabElfHdr(Elf32_Ehdr *pHdrToSwab) static void swabElfHdr(Elf32_Ehdr *pHdrToSwab)
{ {
if (swabRequired == 0) { if (swabRequired == 0) {
return; /* do nothing */ return; /* do nothing */
} }
pHdrToSwab->e_type = SWAB_Elf32_Half(pHdrToSwab->e_type); pHdrToSwab->e_type = SWAB_Elf32_Half(pHdrToSwab->e_type);
pHdrToSwab->e_machine = SWAB_Elf32_Half(pHdrToSwab->e_machine); pHdrToSwab->e_machine = SWAB_Elf32_Half(pHdrToSwab->e_machine);
@ -226,8 +226,8 @@ static void swabElfHdr(Elf32_Ehdr *pHdrToSwab)
static void swabElfSectionHdr(Elf32_Shdr *pHdrToSwab) static void swabElfSectionHdr(Elf32_Shdr *pHdrToSwab)
{ {
if (swabRequired == 0) { if (swabRequired == 0) {
return; /* do nothing */ return; /* do nothing */
} }
pHdrToSwab->sh_name = SWAB_Elf32_Word(pHdrToSwab->sh_name); pHdrToSwab->sh_name = SWAB_Elf32_Word(pHdrToSwab->sh_name);
pHdrToSwab->sh_type = SWAB_Elf32_Word(pHdrToSwab->sh_type); pHdrToSwab->sh_type = SWAB_Elf32_Word(pHdrToSwab->sh_type);
@ -252,8 +252,8 @@ static void swabElfSectionHdr(Elf32_Shdr *pHdrToSwab)
static void swabElfSym(Elf32_Sym *pHdrToSwab) static void swabElfSym(Elf32_Sym *pHdrToSwab)
{ {
if (swabRequired == 0) { if (swabRequired == 0) {
return; /* do nothing */ return; /* do nothing */
} }
pHdrToSwab->st_name = SWAB_Elf32_Word(pHdrToSwab->st_name); pHdrToSwab->st_name = SWAB_Elf32_Word(pHdrToSwab->st_name);
pHdrToSwab->st_value = SWAB_Elf32_Addr(pHdrToSwab->st_value); pHdrToSwab->st_value = SWAB_Elf32_Addr(pHdrToSwab->st_value);
@ -265,11 +265,12 @@ static void swabElfSym(Elf32_Sym *pHdrToSwab)
* *
* ehdrLoad - load the ELF header * ehdrLoad - load the ELF header
* *
* @param fd File descriptor of file from which to read.
*
* RETURNS: 0 on success, -1 on failure * RETURNS: 0 on success, -1 on failure
*/ */
static int ehdrLoad(int fd /* file descriptor of file from which to read */ static int ehdrLoad(int fd)
)
{ {
unsigned ix = 0x12345678; /* used to auto-detect endian-ness */ unsigned ix = 0x12345678; /* used to auto-detect endian-ness */
size_t nBytes; /* number of bytes read from file */ size_t nBytes; /* number of bytes read from file */
@ -280,37 +281,37 @@ static int ehdrLoad(int fd /* file descriptor of file from which to read */
if (nBytes != sizeof(ehdr)) { if (nBytes != sizeof(ehdr)) {
fprintf(stderr, "Failed to read ELF header\n"); fprintf(stderr, "Failed to read ELF header\n");
return -1; return -1;
}
/* perform some rudimentary ELF file validation */
if (strncmp((char *)ehdr.e_ident, ELFMAG, 4) != 0) {
fprintf(stderr, "Input object module not ELF format\n");
return -1;
} }
/* 64-bit ELF module not supported (for now) */ /* perform some rudimentary ELF file validation */
if (strncmp((char *)ehdr.e_ident, ELFMAG, 4) != 0) {
fprintf(stderr, "Input object module not ELF format\n");
return -1;
}
/* 64-bit ELF module not supported (for now) */
if (ehdr.e_ident[EI_CLASS] != ELFCLASS32) { if (ehdr.e_ident[EI_CLASS] != ELFCLASS32) {
fprintf(stderr, "ELF64 class not supported\n"); fprintf(stderr, "ELF64 class not supported\n");
return -1; return -1;
} }
/* /*
* Dynamically determine the endianess of the host (in the absence of * Dynamically determine the endianess of the host (in the absence of
* a compile time macro ala _BYTE_ORDER). The ELF structures will require * a compile time macro ala _BYTE_ORDER). The ELF structures will require
* byte swapping if the host and target have different byte ordering. * byte swapping if the host and target have different byte ordering.
*/ */
if (((*(char *)&ix == 0x78) && (ehdr.e_ident[EI_DATA] == ELFDATA2MSB)) || if (((*(char *)&ix == 0x78) && (ehdr.e_ident[EI_DATA] == ELFDATA2MSB)) ||
((*(char *)&ix == 0x12) && (ehdr.e_ident[EI_DATA] == ELFDATA2LSB))) { ((*(char *)&ix == 0x12) && (ehdr.e_ident[EI_DATA] == ELFDATA2LSB))) {
swabRequired = 1; swabRequired = 1;
DBG_PRINT("Swab required\n"); DBG_PRINT("Swab required\n");
} }
swabElfHdr(&ehdr); /* swap bytes (if required) */ swabElfHdr(&ehdr); /* swap bytes (if required) */
/* debugging: dump some important ELF header fields */ /* debugging: dump some important ELF header fields */
DBG_PRINT("Elf header Magic = %s\n", ehdr.e_ident); DBG_PRINT("Elf header Magic = %s\n", ehdr.e_ident);
DBG_PRINT("Elf header e_type = %d\n", ehdr.e_type); DBG_PRINT("Elf header e_type = %d\n", ehdr.e_type);
@ -324,11 +325,12 @@ static int ehdrLoad(int fd /* file descriptor of file from which to read */
* *
* shdrsLoad - load the section headers * shdrsLoad - load the section headers
* *
* @param fd File descriptor of file from which to read.
*
* RETURNS: 0 on success, -1 on failure * RETURNS: 0 on success, -1 on failure
*/ */
int shdrsLoad(int fd /* file descriptor of file from which to read */ int shdrsLoad(int fd)
)
{ {
size_t nBytes; /* number of bytes read from file */ size_t nBytes; /* number of bytes read from file */
unsigned ix; /* loop index */ unsigned ix; /* loop index */
@ -337,22 +339,22 @@ int shdrsLoad(int fd /* file descriptor of file from which to read */
if (shdr == NULL) { if (shdr == NULL) {
fprintf(stderr, "No memory for section headers!\n"); fprintf(stderr, "No memory for section headers!\n");
return -1; return -1;
} }
/* Seek to the start of the table of section headers */ /* Seek to the start of the table of section headers */
lseek(fd, ehdr.e_shoff, SEEK_SET); lseek(fd, ehdr.e_shoff, SEEK_SET);
for (ix = 0; ix < ehdr.e_shnum; ix++) { for (ix = 0; ix < ehdr.e_shnum; ix++) {
nBytes = read(fd, &shdr[ix], sizeof(Elf32_Shdr)); nBytes = read(fd, &shdr[ix], sizeof(Elf32_Shdr));
if (nBytes != sizeof(Elf32_Shdr)) { if (nBytes != sizeof(Elf32_Shdr)) {
fprintf(stderr, "Unable to read entire section header (#%d)\n", fprintf(stderr, "Unable to read entire section header (#%d)\n",
ix); ix);
return -1; return -1;
}
swabElfSectionHdr(&shdr[ix]); /* swap bytes (if required) */
} }
swabElfSectionHdr(&shdr[ix]); /* swap bytes (if required) */
}
return 0; return 0;
} }
@ -363,23 +365,24 @@ int shdrsLoad(int fd /* file descriptor of file from which to read */
* This routine searches the section headers for the symbol table. There is * This routine searches the section headers for the symbol table. There is
* expected to be only one symbol table in the section headers. * expected to be only one symbol table in the section headers.
* *
* @param pSymTblOffset Pointer to symbol table offset.
* @param pSymTblSize Pointer to symbol table size.
*
* RETURNS: 0 if found, -1 if not * RETURNS: 0 if found, -1 if not
*/ */
int symTblFind(unsigned *pSymTblOffset, /* ptr to symbol table offset */ int symTblFind(unsigned *pSymTblOffset, unsigned *pSymTblSize)
unsigned *pSymTblSize /* ptr to symbol table size */
)
{ {
unsigned ix; /* loop index */ unsigned ix; /* loop index */
for (ix = 0; ix < ehdr.e_shnum; ++ix) { for (ix = 0; ix < ehdr.e_shnum; ++ix) {
if (shdr[ix].sh_type == SHT_SYMTAB) { if (shdr[ix].sh_type == SHT_SYMTAB) {
*pSymTblOffset = shdr[ix].sh_offset; *pSymTblOffset = shdr[ix].sh_offset;
*pSymTblSize = shdr[ix].sh_size; *pSymTblSize = shdr[ix].sh_size;
return 0; return 0;
}
} }
}
fprintf(stderr, "Object module missing symbol table!\n"); fprintf(stderr, "Object module missing symbol table!\n");
@ -404,28 +407,29 @@ int symTblFind(unsigned *pSymTblOffset, /* ptr to symbol table offset */
* 2. If another string table is found, use that only if its section header * 2. If another string table is found, use that only if its section header
* index does not match the index for ".shstrtbl" stored in the ELF header. * index does not match the index for ".shstrtbl" stored in the ELF header.
* *
* @param pStrTblIx Pointer to string table's index.
*
* RETURNS 0 if found, -1 if not * RETURNS 0 if found, -1 if not
*/ */
int strTblFind(unsigned *pStrTblIx /* ptr to string table's index */ int strTblFind(unsigned *pStrTblIx)
)
{ {
unsigned strTblIx = 0xffffffff; unsigned strTblIx = 0xffffffff;
unsigned ix; unsigned ix;
for (ix = 0; ix < ehdr.e_shnum; ++ix) { for (ix = 0; ix < ehdr.e_shnum; ++ix) {
if (shdr[ix].sh_type == SHT_STRTAB) { if (shdr[ix].sh_type == SHT_STRTAB) {
if ((strTblIx == 0xffffffff) || if ((strTblIx == 0xffffffff) ||
(ix != ehdr.e_shstrndx)) { (ix != ehdr.e_shstrndx)) {
strTblIx = ix; strTblIx = ix;
} }
}
} }
}
if (strTblIx == 0xffffffff) { if (strTblIx == 0xffffffff) {
fprintf(stderr, "Object module missing string table!\n"); fprintf(stderr, "Object module missing string table!\n");
return -1; return -1;
} }
*pStrTblIx = strTblIx; *pStrTblIx = strTblIx;
@ -436,25 +440,26 @@ int strTblFind(unsigned *pStrTblIx /* ptr to string table's index */
* *
* strTblLoad - load the string table * strTblLoad - load the string table
* *
* @param fd File descriptor of file from which to read.
* @param strTblIx String table's index.
* @param ppStringTable Pointer to ptr to string table.
*
* RETURNS: 0 on success, -1 on failure * RETURNS: 0 on success, -1 on failure
*/ */
int strTblLoad(int fd, /* file descriptor of file from which to read */ int strTblLoad(int fd, unsigned strTblIx, char **ppStringTable)
unsigned strTblIx, /* string table's index */
char **ppStringTable /* ptr to ptr to string table */
)
{ {
char *pTable; char *pTable;
int nBytes; int nBytes;
DBG_PRINT("Allocating %d bytes for string table\n", DBG_PRINT("Allocating %d bytes for string table\n",
shdr[strTblIx].sh_size); shdr[strTblIx].sh_size);
pTable = malloc(shdr[strTblIx].sh_size); pTable = malloc(shdr[strTblIx].sh_size);
if (pTable == NULL) { if (pTable == NULL) {
fprintf(stderr, "No memory for string table!"); fprintf(stderr, "No memory for string table!");
return -1; return -1;
} }
lseek(fd, shdr[strTblIx].sh_offset, SEEK_SET); lseek(fd, shdr[strTblIx].sh_offset, SEEK_SET);
@ -474,31 +479,32 @@ int strTblLoad(int fd, /* file descriptor of file from which to read */
* *
* headerPreambleDump - dump the header preamble to the header file * headerPreambleDump - dump the header preamble to the header file
* *
* @param fp File pointer to which to write.
* @param filename Name of the output file.
*
* RETURNS: N/A * RETURNS: N/A
*/ */
void headerPreambleDump(FILE *fp, /* file pointer to which to write */ void headerPreambleDump(FILE *fp, char *filename)
char *filename /* name of the output file */
)
{ {
unsigned hash = 5381; /* hash value */ unsigned hash = 5381; /* hash value */
size_t ix; /* loop counter */ size_t ix; /* loop counter */
char fileNameHash[20]; /* '_HGUARD_' + 8 character hash + '\0' */ char fileNameHash[20]; /* '_HGUARD_' + 8 character hash + '\0' */
/* dump header file preamble1[] */ /* dump header file preamble1[] */
fprintf(fp, preamble1, filename, filename, filename); fprintf(fp, preamble1, filename, filename, filename);
/* /*
* Dump header file preamble2[]. Hash file name into something that * Dump header file preamble2[]. Hash file name into something that
* is small enough to be a C macro name and does not have invalid * is small enough to be a C macro name and does not have invalid
* characters for a macro name to use as a header guard. The result * characters for a macro name to use as a header guard. The result
* of the hash should be unique enough for our purposes. * of the hash should be unique enough for our purposes.
*/ */
for (ix = 0; ix < sizeof(filename); ++ix) { for (ix = 0; ix < sizeof(filename); ++ix) {
hash = (hash * 33) + (unsigned int) filename[ix]; hash = (hash * 33) + (unsigned int) filename[ix];
} }
sprintf(fileNameHash, "_HGUARD_%08x", hash); sprintf(fileNameHash, "_HGUARD_%08x", hash);
fprintf(fp, preamble2, fileNameHash, fileNameHash); fprintf(fp, preamble2, fileNameHash, fileNameHash);
@ -508,47 +514,49 @@ void headerPreambleDump(FILE *fp, /* file pointer to which to write */
* *
* headerAbsoluteSymbolsDump - dump the absolute symbols to the header file * headerAbsoluteSymbolsDump - dump the absolute symbols to the header file
* *
* @param fd File descriptor of file from which to read.
* @param fp File pointer to which to write.
* @param symTblOffset Symbol table offset.
* @param symTblSize Size of the symbol table.
* @param pStringTable Pointer to the string table.
*
* RETURNS: N/A * RETURNS: N/A
*/ */
void headerAbsoluteSymbolsDump(int fd, /* file descriptor of file from which to read */ void headerAbsoluteSymbolsDump(int fd, FILE *fp, Elf32_Off symTblOffset,
FILE *fp, /* file pointer to which to write */ Elf32_Word symTblSize, char *pStringTable)
Elf32_Off symTblOffset, /* symbol table offset */
Elf32_Word symTblSize, /* size of the symbol table */
char *pStringTable /* ptr to the string table */
)
{ {
Elf32_Sym aSym; /* absolute symbol */ Elf32_Sym aSym; /* absolute symbol */
unsigned ix; /* loop counter */ unsigned ix; /* loop counter */
unsigned numSyms; /* number of symbols in the symbol table */ unsigned numSyms; /* number of symbols in the symbol table */
/* context the symbol table: pick out absolute syms */ /* context the symbol table: pick out absolute syms */
numSyms = symTblSize / sizeof(Elf32_Sym); numSyms = symTblSize / sizeof(Elf32_Sym);
lseek(fd, symTblOffset, SEEK_SET); lseek(fd, symTblOffset, SEEK_SET);
for (ix = 0; ix < numSyms; ++ix) { for (ix = 0; ix < numSyms; ++ix) {
/* read in a single symbol structure */ /* read in a single symbol structure */
read(fd, &aSym, sizeof(Elf32_Sym)); read(fd, &aSym, sizeof(Elf32_Sym));
swabElfSym(&aSym); /* swap bytes (if required) */ swabElfSym(&aSym); /* swap bytes (if required) */
/* /*
* Only generate definitions for global absolute symbols * Only generate definitions for global absolute symbols
* of the form *_OFFSET * of the form *_OFFSET
*/ */
if ((aSym.st_shndx == SHN_ABS) && if ((aSym.st_shndx == SHN_ABS) &&
(ELF_ST_BIND(aSym.st_info) == STB_GLOBAL)) { (ELF_ST_BIND(aSym.st_info) == STB_GLOBAL)) {
if ((strstr(&pStringTable[aSym.st_name], if ((strstr(&pStringTable[aSym.st_name],
STRUCT_OFF_SUFFIX) != NULL) || STRUCT_OFF_SUFFIX) != NULL) ||
(strstr(&pStringTable[aSym.st_name], (strstr(&pStringTable[aSym.st_name],
STRUCT_SIZ_SUFFIX) != NULL)) { STRUCT_SIZ_SUFFIX) != NULL)) {
fprintf(fp, "#define\t%s\t0x%X\n", fprintf(fp, "#define\t%s\t0x%X\n",
&pStringTable[aSym.st_name], aSym.st_value); &pStringTable[aSym.st_name], aSym.st_value);
} }
} }
} }
} }
@ -556,11 +564,12 @@ void headerAbsoluteSymbolsDump(int fd, /* file descriptor of file from which t
* *
* headerPostscriptDump - dump the header postscript to the header file * headerPostscriptDump - dump the header postscript to the header file
* *
* @param fp File pointer to which to write.
*
* RETURNS: N/A * RETURNS: N/A
*/ */
void headerPostscriptDump(FILE *fp /* file pointer to which to write */ void headerPostscriptDump(FILE *fp)
)
{ {
fputs(postscript, fp); fputs(postscript, fp);
} }
@ -586,52 +595,52 @@ int main(int argc, char *argv[])
FILE *outFile = NULL; FILE *outFile = NULL;
unsigned strTblIx; unsigned strTblIx;
/* argument parsing */ /* argument parsing */
if (argc != 5) { if (argc != 5) {
fprintf(stderr, usage, argv[0]); fprintf(stderr, usage, argv[0]);
goto errorReturn; goto errorReturn;
} }
while ((option = getopt(argc, argv, "i:o:")) != -1) { while ((option = getopt(argc, argv, "i:o:")) != -1) {
switch (option) { switch (option) {
case 'i': case 'i':
inFileName = optarg; inFileName = optarg;
break; break;
case 'o': case 'o':
outFileName = optarg; outFileName = optarg;
break; break;
default: default:
fprintf(stderr, usage, argv[0]); fprintf(stderr, usage, argv[0]);
goto errorReturn; goto errorReturn;
} }
} }
/* open input object ELF module and output header file */ /* open input object ELF module and output header file */
inFd = open(inFileName, OPEN_FLAGS); inFd = open(inFileName, OPEN_FLAGS);
if (inFd == -1) { if (inFd == -1) {
fprintf(stderr, "Cannot open input object module"); fprintf(stderr, "Cannot open input object module");
goto errorReturn; goto errorReturn;
} }
outFile = fopen(outFileName, "w"); outFile = fopen(outFileName, "w");
if (outFile == NULL) { if (outFile == NULL) {
fprintf(stderr, "Cannot open output header file"); fprintf(stderr, "Cannot open output header file");
goto errorReturn; goto errorReturn;
} }
/* /*
* In the following order, attempt to ... * In the following order, attempt to ...
* 1. Load the ELF header * 1. Load the ELF header
* 2. Load the section headers * 2. Load the section headers
* 3. Find the symbol table * 3. Find the symbol table
* 4. Find the string table * 4. Find the string table
* 5. Load the string table * 5. Load the string table
* Bail if any of those steps fail. * Bail if any of those steps fail.
*/ */
if ((ehdrLoad(inFd) != 0) || if ((ehdrLoad(inFd) != 0) ||
(shdrsLoad(inFd) != 0) || (shdrsLoad(inFd) != 0) ||
@ -639,22 +648,22 @@ int main(int argc, char *argv[])
(strTblFind(&strTblIx) != 0) || (strTblFind(&strTblIx) != 0) ||
(strTblLoad(inFd, strTblIx, &pStringTable) != 0)) { (strTblLoad(inFd, strTblIx, &pStringTable) != 0)) {
goto errorReturn; goto errorReturn;
} }
/* /*
* Dump the following to the header file ... * Dump the following to the header file ...
* 1. Header file preamble * 1. Header file preamble
* 2. Absolute symbols * 2. Absolute symbols
* 3. Header file postscript * 3. Header file postscript
*/ */
headerPreambleDump(outFile, outFileName); headerPreambleDump(outFile, outFileName);
headerAbsoluteSymbolsDump(inFd, outFile, headerAbsoluteSymbolsDump(inFd, outFile,
symTblOffset, symTblSize, pStringTable); symTblOffset, symTblSize, pStringTable);
headerPostscriptDump(outFile); headerPostscriptDump(outFile);
/* done: cleanup */ /* done: cleanup */
close(inFd); close(inFd);
fclose(outFile); fclose(outFile);
@ -666,19 +675,19 @@ int main(int argc, char *argv[])
errorReturn: errorReturn:
if (inFd != -1) { if (inFd != -1) {
close(inFd); close(inFd);
} }
if (outFile != NULL) { if (outFile != NULL) {
fclose(outFile); fclose(outFile);
} }
if (shdr != NULL) { if (shdr != NULL) {
free(shdr); free(shdr);
} }
if (pStringTable != NULL) { if (pStringTable != NULL) {
free(pStringTable); free(pStringTable);
} }
return 1; return 1;
} }

View file

@ -122,7 +122,7 @@ static void get_options(int argc, char *argv[])
exit(-1); exit(-1);
} }
} }
for(ii = IFILE; ii < NUSERFILES; ii++) { for (ii = IFILE; ii < NUSERFILES; ii++) {
if (!filenames[ii]) { if (!filenames[ii]) {
usage(SHORT_USAGE); usage(SHORT_USAGE);
exit(-1); exit(-1);
@ -139,12 +139,12 @@ static void open_files(void)
fds[IFILE] = open_binary(filenames[IFILE], O_RDONLY); fds[IFILE] = open_binary(filenames[IFILE], O_RDONLY);
fds[OFILE] = open(filenames[OFILE], open_w_flags, open_mode); fds[OFILE] = open(filenames[OFILE], open_w_flags, open_mode);
for(ii = 0; ii < NUSERFILES; ii++) { for (ii = 0; ii < NUSERFILES; ii++) {
int invalid = fds[ii] == -1; int invalid = fds[ii] == -1;
if (invalid) { if (invalid) {
const char *invalid = filenames[ii]; const char *invalid = filenames[ii];
fprintf(stderr, "invalid file %s\n", invalid); fprintf(stderr, "invalid file %s\n", invalid);
for(--ii; ii >= 0; ii--) { for (--ii; ii >= 0; ii--) {
close(fds[ii]); close(fds[ii]);
} }
exit(-1); exit(-1);
@ -229,7 +229,7 @@ static void close_files(void)
{ {
int ii; int ii;
for(ii = 0; ii < NUSERFILES; ii++) { for (ii = 0; ii < NUSERFILES; ii++) {
close(fds[ii]); close(fds[ii]);
} }
} }

View file

@ -40,31 +40,34 @@ in decimal notation. Each event object is outputted on stdout.
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
void usage( /*******************************************************************************
char *progname /* name of the program to use */ *
) * @param progname Name of the program to use.
{ *
* RETURNS: N/A
*/
void usage(char *progname)
{
fprintf(stderr, "Utility creates a series of microkernel VPF event objects. Output is sent to stdout.\n"); fprintf(stderr, "Utility creates a series of microkernel VPF event objects. Output is sent to stdout.\n");
fprintf(stderr, "Usage: %s <decimal number>\n", progname); fprintf(stderr, "Usage: %s <decimal number>\n", progname);
} }
#define EVENT_STR " EVENT _TaskIrqEvt%d NULL\n" #define EVENT_STR " EVENT _TaskIrqEvt%d NULL\n"
int main( int main(int argc, char *argv[])
int argc, {
char *argv[]
)
{
int i, j; int i, j;
if (argc != 2) { if (argc != 2) {
usage(argv[0]); usage(argv[0]);
return -1; return -1;
} }
j = atoi(argv[1]); j = atoi(argv[1]);
for (i = 0; i < j; i++) for (i = 0; i < j; i++) {
printf(EVENT_STR, i); printf(EVENT_STR, i);
}
return 0; return 0;
} }

View file

@ -665,7 +665,7 @@ struct _pci_msi_hdr {
struct { struct {
/* offset 04: */ /* offset 04: */
uint32_t addr; /* message address register */ uint32_t addr; /* message address register */
/* offset 08: */ /* offset 08: */
uint32_t data : 16; /* message data register uint32_t data : 16; /* message data register
*/ */
uint32_t spare uint32_t spare
@ -1017,7 +1017,7 @@ extern int pci_config_ext_cap_ptr_find(
/* Fixed addr */ /* Fixed addr */
#define HT_MSI_FIXED_ADDR 0x00000000FEE00000ULL #define HT_MSI_FIXED_ADDR 0x00000000FEE00000ULL
#define HT_MSI_ADDR_LO 0x04 /* Offset to low addr bits */ #define HT_MSI_ADDR_LO 0x04 /* Offset to low addr bits */
/* Low address bit mask */ /* Low address bit mask */
#define HT_MSI_ADDR_LO_MASK 0xFFF00000 #define HT_MSI_ADDR_LO_MASK 0xFFF00000
#define HT_MSI_ADDR_HI 0x08 /* Offset to high addr bits */ #define HT_MSI_ADDR_HI 0x08 /* Offset to high addr bits */
#define HT_CAPTYPE_DIRECT_ROUTE 0xB0 /* Direct routing configuration */ #define HT_CAPTYPE_DIRECT_ROUTE 0xB0 /* Direct routing configuration */
@ -1045,7 +1045,7 @@ extern int pci_config_ext_cap_ptr_find(
#define PCIE_ATS_MAX_QDEP 32 /* Max Invalidate Queue Depth */ #define PCIE_ATS_MAX_QDEP 32 /* Max Invalidate Queue Depth */
#define PCIE_ATS_CTRL 0x06 /* ATS Control Register */ #define PCIE_ATS_CTRL 0x06 /* ATS Control Register */
#define PCIE_ATS_CTRL_ENABLE 0x8000 /* ATS Enable */ #define PCIE_ATS_CTRL_ENABLE 0x8000 /* ATS Enable */
/* Smallest Translation Unit */ /* Smallest Translation Unit */
#define PCIE_ATS_CTRL_STU(x) ((x) & 0x1f) #define PCIE_ATS_CTRL_STU(x) ((x) & 0x1f)
#define PCIE_ATS_MIN_STU 12 /* shift of minimum STU block */ #define PCIE_ATS_MIN_STU 12 /* shift of minimum STU block */

View file

@ -248,7 +248,7 @@ void _int_latency_stop(void);
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
unsigned int irq_lock_inline(void) unsigned int irq_lock_inline(void)
{ {
unsigned int key = _do_irq_lock_inline(); unsigned int key = _do_irq_lock_inline();
#ifdef CONFIG_INT_LATENCY_BENCHMARK #ifdef CONFIG_INT_LATENCY_BENCHMARK
@ -256,7 +256,7 @@ static inline __attribute__((always_inline))
#endif #endif
return key; return key;
} }
/******************************************************************************* /*******************************************************************************
@ -276,15 +276,16 @@ static inline __attribute__((always_inline))
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
void irq_unlock_inline(unsigned int key) void irq_unlock_inline(unsigned int key)
{ {
if (!(key & 0x200)) if (!(key & 0x200)) {
return; return;
}
#ifdef CONFIG_INT_LATENCY_BENCHMARK #ifdef CONFIG_INT_LATENCY_BENCHMARK
_int_latency_stop(); _int_latency_stop();
#endif #endif
_do_irq_unlock_inline(); _do_irq_unlock_inline();
return; return;
} }
#endif /* CONFIG_NO_ISRS */ #endif /* CONFIG_NO_ISRS */
/* interrupt/exception/error related definitions */ /* interrupt/exception/error related definitions */

View file

@ -407,16 +407,16 @@ static inline void k_memcpy(void *_d, const void *_s, size_t _n)
/* _d & _s must be aligned to use movsl. */ /* _d & _s must be aligned to use movsl. */
#ifndef CONFIG_UNALIGNED_WRITE_UNSUPPORTED #ifndef CONFIG_UNALIGNED_WRITE_UNSUPPORTED
if ((_n&3) == 0) { if ((_n&3) == 0) {
/* _n is multiple of words, much more efficient to do word moves */ /* _n is multiple of words, much more efficient to do word moves */
_n >>= 2; _n >>= 2;
__asm__ volatile ("rep movsl" : __asm__ volatile ("rep movsl" :
"+D" (_d), "+S" (_s), "+c" (_n) : "+D" (_d), "+S" (_s), "+c" (_n) :
: :
"cc", "memory"); "cc", "memory");
} else } else
#endif /* CONFIG_UNALIGNED_WRITE_UNSUPPORTED */ #endif /* CONFIG_UNALIGNED_WRITE_UNSUPPORTED */
{ {
__asm__ volatile ("rep movsb" : __asm__ volatile ("rep movsb" :
"+D" (_d), "+S" (_s), "+c" (_n) : "+D" (_d), "+S" (_s), "+c" (_n) :
: :
"cc", "memory"); "cc", "memory");
@ -440,11 +440,11 @@ static inline void k_memset(void *_d, int _v, size_t _n)
/* _d must be aligned to use stosl. */ /* _d must be aligned to use stosl. */
#ifndef CONFIG_UNALIGNED_WRITE_UNSUPPORTED #ifndef CONFIG_UNALIGNED_WRITE_UNSUPPORTED
if ((_n&3) == 0) { if ((_n&3) == 0) {
/* _n is multiple of words, much more efficient to do word stores */ /* _n is multiple of words, much more efficient to do word stores */
_n >>= 2; _n >>= 2;
_v |= _v<<8; _v |= _v<<8;
_v |= _v<<16; _v |= _v<<16;
__asm__ volatile ("rep stosl" : __asm__ volatile ("rep stosl" :
"+D" (_d), "+c" (_n) : "+D" (_d), "+c" (_n) :
"a" (_v) : "a" (_v) :
"cc", "memory"); "cc", "memory");

View file

@ -97,8 +97,7 @@ void BuffReset(struct chbuff *pChBuff)
ReadMarkersClear(pChBuff); ReadMarkersClear(pChBuff);
} }
void BuffGetFreeSpaceTotal(struct chbuff *pChBuff, void BuffGetFreeSpaceTotal(struct chbuff *pChBuff, int *piFreeSpaceTotal)
int *piFreeSpaceTotal)
{ {
int dummy1, dummy2; int dummy1, dummy2;
*piFreeSpaceTotal = CalcFreeSpace(pChBuff, &dummy1, &dummy2); *piFreeSpaceTotal = CalcFreeSpace(pChBuff, &dummy1, &dummy2);
@ -106,10 +105,8 @@ void BuffGetFreeSpaceTotal(struct chbuff *pChBuff,
__ASSERT_NO_MSG(dummy2 == pChBuff->iFreeSpaceAWA); __ASSERT_NO_MSG(dummy2 == pChBuff->iFreeSpaceAWA);
} }
void BuffGetFreeSpace(struct chbuff *pChBuff, void BuffGetFreeSpace(struct chbuff *pChBuff, int *piFreeSpaceTotal,
int *piFreeSpaceTotal, int *piFreeSpaceCont, int *piFreeSpaceAWA)
int *piFreeSpaceCont,
int *piFreeSpaceAWA)
{ {
int iFreeSpaceCont; int iFreeSpaceCont;
int iFreeSpaceAWA; int iFreeSpaceAWA;
@ -124,8 +121,7 @@ void BuffGetFreeSpace(struct chbuff *pChBuff,
*piFreeSpaceAWA = pChBuff->iFreeSpaceAWA; *piFreeSpaceAWA = pChBuff->iFreeSpaceAWA;
} }
void BuffGetAvailDataTotal(struct chbuff *pChBuff, void BuffGetAvailDataTotal(struct chbuff *pChBuff, int *piAvailDataTotal)
int *piAvailDataTotal)
{ {
int dummy1, dummy2; int dummy1, dummy2;
*piAvailDataTotal = CalcAvailData(pChBuff, &dummy1, &dummy2); *piAvailDataTotal = CalcAvailData(pChBuff, &dummy1, &dummy2);
@ -133,10 +129,8 @@ void BuffGetAvailDataTotal(struct chbuff *pChBuff,
__ASSERT_NO_MSG(dummy2 == pChBuff->iAvailDataAWA); __ASSERT_NO_MSG(dummy2 == pChBuff->iAvailDataAWA);
} }
void BuffGetAvailData(struct chbuff *pChBuff, void BuffGetAvailData(struct chbuff *pChBuff, int *piAvailDataTotal,
int *piAvailDataTotal, int *piAvailDataCont, int *piAvailDataAWA)
int *piAvailDataCont,
int *piAvailDataAWA)
{ {
int iAvailDataCont; int iAvailDataCont;
int iAvailDataAWA; int iAvailDataAWA;
@ -159,23 +153,25 @@ int BuffEnQ(struct chbuff *pChBuff, int iSize, unsigned char **ppWrite)
{ {
int iTransferID; int iTransferID;
/* int ret;*/ /* int ret;*/
if (0 == BuffEnQA(pChBuff, iSize, ppWrite, &iTransferID)) if (0 == BuffEnQA(pChBuff, iSize, ppWrite, &iTransferID)) {
return 0; return 0;
BuffEnQA_End(pChBuff, iTransferID, iSize /*optional */); /* check ret }
value */
/* check ret value */
BuffEnQA_End(pChBuff, iTransferID, iSize /*optional */);
return iSize; return iSize;
} }
int BuffEnQA(struct chbuff *pChBuff, int BuffEnQA(struct chbuff *pChBuff, int iSize, unsigned char **ppWrite,
int iSize, int *piTransferID)
unsigned char **ppWrite,
int *piTransferID)
{ {
if (iSize > pChBuff->iFreeSpaceCont) if (iSize > pChBuff->iFreeSpaceCont) {
return 0; return 0;
}
*piTransferID = AsyncEnQRegstr(pChBuff, iSize); *piTransferID = AsyncEnQRegstr(pChBuff, iSize);
if (-1 == *piTransferID) if (-1 == *piTransferID) {
return 0; return 0;
}
*ppWrite = pChBuff->pWrite; *ppWrite = pChBuff->pWrite;
@ -193,19 +189,20 @@ int BuffEnQA(struct chbuff *pChBuff,
pChBuff->iFreeSpaceCont -= iSize; pChBuff->iFreeSpaceCont -= iSize;
} }
if (pChBuff->pWrite == pChBuff->pRead) if (pChBuff->pWrite == pChBuff->pRead) {
pChBuff->BuffState = BUFF_FULL; pChBuff->BuffState = BUFF_FULL;
else }
else {
pChBuff->BuffState = BUFF_OTHER; pChBuff->BuffState = BUFF_OTHER;
}
CHECK_CHBUFF_POINTER(pChBuff->pWrite); CHECK_CHBUFF_POINTER(pChBuff->pWrite);
return iSize; return iSize;
} }
void BuffEnQA_End(struct chbuff *pChBuff, void BuffEnQA_End(struct chbuff *pChBuff, int iTransferID,
int iTransferID, int iSize /*optional */)
int iSize /*optional */)
{ {
ARG_UNUSED(iSize); ARG_UNUSED(iSize);
@ -228,14 +225,16 @@ int AsyncEnQRegstr(struct chbuff *pChBuff, int iSize)
__ASSERT_NO_MSG(0 <= pChBuff->iNbrPendingWrites); __ASSERT_NO_MSG(0 <= pChBuff->iNbrPendingWrites);
(pChBuff->iNbrPendingWrites)++; (pChBuff->iNbrPendingWrites)++;
/* pReadGuard changes? */ /* pReadGuard changes? */
if (NULL == pChBuff->pReadGuard) if (NULL == pChBuff->pReadGuard) {
pChBuff->pReadGuard = pChBuff->pWrite; pChBuff->pReadGuard = pChBuff->pWrite;
}
__ASSERT_NO_MSG(pChBuff->WriteMarkers.aMarkers __ASSERT_NO_MSG(pChBuff->WriteMarkers.aMarkers
[pChBuff->WriteMarkers.iFirstMarker] [pChBuff->WriteMarkers.iFirstMarker]
.pointer == pChBuff->pReadGuard); .pointer == pChBuff->pReadGuard);
/* iAWAMarker changes? */ /* iAWAMarker changes? */
if (-1 == pChBuff->WriteMarkers.iAWAMarker && pChBuff->bWriteWA) if (-1 == pChBuff->WriteMarkers.iAWAMarker && pChBuff->bWriteWA) {
pChBuff->WriteMarkers.iAWAMarker = i; pChBuff->WriteMarkers.iAWAMarker = i;
}
} }
return i; return i;
} }
@ -249,17 +248,19 @@ void AsyncEnQFinished(struct chbuff *pChBuff, int iTransferID)
int isizeAWA=0; */ int isizeAWA=0; */
int iNewFirstMarker = int iNewFirstMarker =
ScanMarkers(&(pChBuff->WriteMarkers), ScanMarkers(&(pChBuff->WriteMarkers),
&(pChBuff->iAvailDataCont), &(pChBuff->iAvailDataCont),
&(pChBuff->iAvailDataAWA), &(pChBuff->iAvailDataAWA),
&(pChBuff->iNbrPendingWrites)); &(pChBuff->iNbrPendingWrites));
/*pChBuff->iAvailDataCont +=iSizeCont; /*pChBuff->iAvailDataCont +=iSizeCont;
pChBuff->iAvailDataAWA +=iSizeAWA; */ pChBuff->iAvailDataAWA +=iSizeAWA; */
if (-1 != iNewFirstMarker) if (-1 != iNewFirstMarker) {
pChBuff->pReadGuard = pChBuff->pReadGuard =
pChBuff->WriteMarkers.aMarkers[iNewFirstMarker] pChBuff->WriteMarkers.aMarkers[iNewFirstMarker]
.pointer; .pointer;
else }
else {
pChBuff->pReadGuard = NULL; pChBuff->pReadGuard = NULL;
}
} }
} }
@ -271,27 +272,27 @@ int BuffDeQ(struct chbuff *pChBuff, int iSize, unsigned char **ppRead)
{ {
int iTransferID; int iTransferID;
/* int ret;*/ /* int ret;*/
if (0 == BuffDeQA(pChBuff, iSize, ppRead, &iTransferID)) if (0 == BuffDeQA(pChBuff, iSize, ppRead, &iTransferID)) {
return 0; return 0;
}
BuffDeQA_End(pChBuff, iTransferID, iSize /*optional */); BuffDeQA_End(pChBuff, iTransferID, iSize /*optional */);
return iSize; return iSize;
} }
int BuffDeQA(struct chbuff *pChBuff, int BuffDeQA(struct chbuff *pChBuff, int iSize, unsigned char **ppRead,
int iSize, int *piTransferID)
unsigned char **ppRead,
int *piTransferID)
{ {
/* asynchronous data transfer /* asynchronous data transfer
read guard pointers must be set * read guard pointers must be set
*/ */
if (iSize > if (iSize > pChBuff->iAvailDataCont) {
pChBuff->iAvailDataCont) /* free space is from read to guard /* free space is from read to guard pointer/end pointer */
pointer/end pointer */
return 0; return 0;
}
*piTransferID = AsyncDeQRegstr(pChBuff, iSize); *piTransferID = AsyncDeQRegstr(pChBuff, iSize);
if (-1 == *piTransferID) if (-1 == *piTransferID) {
return 0; return 0;
}
*ppRead = pChBuff->pRead; *ppRead = pChBuff->pRead;
@ -309,19 +310,20 @@ int BuffDeQA(struct chbuff *pChBuff,
pChBuff->iAvailDataCont -= iSize; pChBuff->iAvailDataCont -= iSize;
} }
if (pChBuff->pWrite == pChBuff->pRead) if (pChBuff->pWrite == pChBuff->pRead) {
pChBuff->BuffState = BUFF_EMPTY; pChBuff->BuffState = BUFF_EMPTY;
else }
else {
pChBuff->BuffState = BUFF_OTHER; pChBuff->BuffState = BUFF_OTHER;
}
CHECK_CHBUFF_POINTER(pChBuff->pRead); CHECK_CHBUFF_POINTER(pChBuff->pRead);
return iSize; return iSize;
} }
void BuffDeQA_End(struct chbuff *pChBuff, void BuffDeQA_End(struct chbuff *pChBuff, int iTransferID,
int iTransferID, int iSize /*optional */)
int iSize /*optional */)
{ {
ARG_UNUSED(iSize); ARG_UNUSED(iSize);
@ -358,14 +360,16 @@ int AsyncDeQRegstr(struct chbuff *pChBuff, int iSize)
__ASSERT_NO_MSG(0 <= pChBuff->iNbrPendingReads); __ASSERT_NO_MSG(0 <= pChBuff->iNbrPendingReads);
(pChBuff->iNbrPendingReads)++; (pChBuff->iNbrPendingReads)++;
/* pWriteGuard changes? */ /* pWriteGuard changes? */
if (NULL == pChBuff->pWriteGuard) if (NULL == pChBuff->pWriteGuard) {
pChBuff->pWriteGuard = pChBuff->pRead; pChBuff->pWriteGuard = pChBuff->pRead;
}
__ASSERT_NO_MSG(pChBuff->ReadMarkers.aMarkers __ASSERT_NO_MSG(pChBuff->ReadMarkers.aMarkers
[pChBuff->ReadMarkers.iFirstMarker] [pChBuff->ReadMarkers.iFirstMarker]
.pointer == pChBuff->pWriteGuard); .pointer == pChBuff->pWriteGuard);
/* iAWAMarker changes? */ /* iAWAMarker changes? */
if (-1 == pChBuff->ReadMarkers.iAWAMarker && pChBuff->bReadWA) if (-1 == pChBuff->ReadMarkers.iAWAMarker && pChBuff->bReadWA) {
pChBuff->ReadMarkers.iAWAMarker = i; pChBuff->ReadMarkers.iAWAMarker = i;
}
} }
return i; return i;
} }
@ -383,12 +387,14 @@ void AsyncDeQFinished(struct chbuff *pChBuff, int iTransferID)
&(pChBuff->iNbrPendingReads)); &(pChBuff->iNbrPendingReads));
/*pChBuff->iFreeSpaceCont +=iSizeCont; /*pChBuff->iFreeSpaceCont +=iSizeCont;
pChBuff->iFreeSpaceAWA +=iSizeAWA; */ pChBuff->iFreeSpaceAWA +=iSizeAWA; */
if (-1 != iNewFirstMarker) if (-1 != iNewFirstMarker) {
pChBuff->pWriteGuard = pChBuff->pWriteGuard =
pChBuff->ReadMarkers.aMarkers[iNewFirstMarker] pChBuff->ReadMarkers.aMarkers[iNewFirstMarker]
.pointer; .pointer;
else }
else {
pChBuff->pWriteGuard = NULL; pChBuff->pWriteGuard = NULL;
}
} }
} }
@ -430,10 +436,8 @@ available
(either for writing xor reading). (either for writing xor reading).
Note: such a series of areas starts from the beginning. Note: such a series of areas starts from the beginning.
*/ */
int ScanMarkers(struct marker_list *pMarkerList, int ScanMarkers(struct marker_list *pMarkerList, int *piSizeBWA,
int *piSizeBWA, int *piSizeAWA, int *piNbrPendingXfers)
int *piSizeAWA,
int *piNbrPendingXfers)
{ {
struct marker *pM; struct marker *pM;
BOOL bMarkersAreNowAWA; BOOL bMarkersAreNowAWA;
@ -458,17 +462,20 @@ int ScanMarkers(struct marker_list *pMarkerList,
pM = &(pMarkerList->aMarkers[index]); pM = &(pMarkerList->aMarkers[index]);
if (pM->bXferBusy == TRUE) if (pM->bXferBusy == TRUE) {
break; break;
}
if (!bMarkersAreNowAWA) if (!bMarkersAreNowAWA) {
*piSizeBWA += pM->size; *piSizeBWA += pM->size;
else }
else {
*piSizeAWA += pM->size; *piSizeAWA += pM->size;
}
index_next = pM->Next; index_next = pM->Next;
MarkerDelete(pMarkerList, index); /* pMarkerList->iFirstMarker /* pMarkerList->iFirstMarker will be updated */
will be updated */ MarkerDelete(pMarkerList, index);
/* adjust *piNbrPendingXfers */ /* adjust *piNbrPendingXfers */
if (piNbrPendingXfers) { if (piNbrPendingXfers) {
__ASSERT_NO_MSG(0 <= *piNbrPendingXfers); __ASSERT_NO_MSG(0 <= *piNbrPendingXfers);
@ -479,8 +486,9 @@ int ScanMarkers(struct marker_list *pMarkerList,
__ASSERT_NO_MSG(index == pMarkerList->iFirstMarker); __ASSERT_NO_MSG(index == pMarkerList->iFirstMarker);
if (bMarkersAreNowAWA) if (bMarkersAreNowAWA) {
pMarkerList->iAWAMarker = pMarkerList->iFirstMarker; pMarkerList->iAWAMarker = pMarkerList->iFirstMarker;
}
#ifdef STORE_NBR_MARKERS #ifdef STORE_NBR_MARKERS
if (0 == pMarkerList->iNbrMarkers) { if (0 == pMarkerList->iNbrMarkers) {
@ -495,15 +503,15 @@ int ScanMarkers(struct marker_list *pMarkerList,
/**********************************************************/ /**********************************************************/
int CalcAvailData(struct chbuff *pChBuff, int CalcAvailData(struct chbuff *pChBuff, int *piAvailDataCont,
int *piAvailDataCont, int *piAvailDataAWA)
int *piAvailDataAWA)
{ {
unsigned char *pStart = pChBuff->pRead; unsigned char *pStart = pChBuff->pRead;
unsigned char *pStop = pChBuff->pWrite; unsigned char *pStop = pChBuff->pWrite;
if (NULL != pChBuff->pReadGuard) if (NULL != pChBuff->pReadGuard) {
pStop = pChBuff->pReadGuard; pStop = pChBuff->pReadGuard;
}
else { else {
/* else: /* else:
if BuffState==BUFF_FULL but we have a ReadGuard, we still if BuffState==BUFF_FULL but we have a ReadGuard, we still
@ -532,15 +540,15 @@ int CalcAvailData(struct chbuff *pChBuff,
return (*piAvailDataCont + *piAvailDataAWA); return (*piAvailDataCont + *piAvailDataAWA);
} }
int CalcFreeSpace(struct chbuff *pChBuff, int CalcFreeSpace(struct chbuff *pChBuff, int *piFreeSpaceCont,
int *piFreeSpaceCont, int *piFreeSpaceAWA)
int *piFreeSpaceAWA)
{ {
unsigned char *pStart = pChBuff->pWrite; unsigned char *pStart = pChBuff->pWrite;
unsigned char *pStop = pChBuff->pRead; unsigned char *pStop = pChBuff->pRead;
if (NULL != pChBuff->pWriteGuard) if (NULL != pChBuff->pWriteGuard) {
pStop = pChBuff->pWriteGuard; pStop = pChBuff->pWriteGuard;
}
else { else {
/* else: /* else:
if BuffState==BUFF_EMPTY but we have a WriteGuard, we still if BuffState==BUFF_EMPTY but we have a WriteGuard, we still

View file

@ -266,10 +266,12 @@ int task_workload_get(void)
void workload_time_slice_set(int32_t t) void workload_time_slice_set(int32_t t)
{ {
#ifdef CONFIG_WORKLOAD_MONITOR #ifdef CONFIG_WORKLOAD_MONITOR
if (t < 10) if (t < 10) {
t = 10; t = 10;
if (t > 1000) }
if (t > 1000) {
t = 1000; t = 1000;
}
_k_workload_slice = t; _k_workload_slice = t;
#else #else
ARG_UNUSED(t); ARG_UNUSED(t);
@ -386,8 +388,9 @@ void _sys_power_save_idle_exit(int32_t ticks)
static inline int32_t _get_next_timer_expiry(void) static inline int32_t _get_next_timer_expiry(void)
{ {
if (_k_timer_list_head) if (_k_timer_list_head) {
return _k_timer_list_head->duration; return _k_timer_list_head->duration;
}
return TICKS_UNLIMITED; return TICKS_UNLIMITED;
} }

View file

@ -66,10 +66,12 @@ static void signal_semaphore(int n, struct sem_struct *S)
#endif #endif
{ {
S->Level--; S->Level--;
if (Y) if (Y) {
Y->Forw = X; Y->Forw = X;
else }
else {
S->Waiters = X; S->Waiters = X;
}
#ifdef CONFIG_SYS_CLOCK_EXISTS #ifdef CONFIG_SYS_CLOCK_EXISTS
if (A->Time.timer) { if (A->Time.timer) {
force_timeout(A); force_timeout(A);
@ -77,7 +79,7 @@ static void signal_semaphore(int n, struct sem_struct *S)
} else { } else {
#endif #endif
A->Time.rcode = RC_OK; A->Time.rcode = RC_OK;
reset_state_bit(A->Ctxt.proc, TF_SEMA); reset_state_bit(A->Ctxt.proc, TF_SEMA);
#ifdef CONFIG_SYS_CLOCK_EXISTS #ifdef CONFIG_SYS_CLOCK_EXISTS
} }
#endif #endif
@ -90,8 +92,9 @@ static void signal_semaphore(int n, struct sem_struct *S)
SENDARGS(Y); SENDARGS(Y);
Y = A; Y = A;
} }
else else {
Y = A; Y = A;
}
A = X; A = X;
} }
} }
@ -108,8 +111,9 @@ void _k_sem_group_wait(struct k_args *R)
struct k_args *A = R->Ctxt.args; struct k_args *A = R->Ctxt.args;
FREEARGS(R); FREEARGS(R);
if (--(A->Args.s1.nsem) == 0) if (--(A->Args.s1.nsem) == 0) {
reset_state_bit(A->Ctxt.proc, TF_LIST); reset_state_bit(A->Ctxt.proc, TF_LIST);
}
} }
/******************************************************************************* /*******************************************************************************
@ -132,10 +136,12 @@ void _k_sem_group_wait_cancel(struct k_args *A)
while (X && (X->Prio <= A->Prio)) { while (X && (X->Prio <= A->Prio)) {
if (X->Ctxt.args == A->Ctxt.args) { if (X->Ctxt.args == A->Ctxt.args) {
if (Y) if (Y) {
Y->Forw = X->Forw; Y->Forw = X->Forw;
else }
else {
S->Waiters = X->Forw; S->Waiters = X->Forw;
}
if (X->Comm == WAITMREQ || X->Comm == WAITMRDY) { if (X->Comm == WAITMREQ || X->Comm == WAITMRDY) {
if (X->Comm == WAITMRDY) { if (X->Comm == WAITMRDY) {
/* obtain struct k_args of waiting task */ /* obtain struct k_args of waiting task */
@ -150,18 +156,19 @@ void _k_sem_group_wait_cancel(struct k_args *A)
* timer expiry occurs between the update of the packet state * timer expiry occurs between the update of the packet state
* and the processing of the WAITMRDY packet. * and the processing of the WAITMRDY packet.
*/ */
if (unlikely(waitTaskArgs->Args.s1 if (unlikely(waitTaskArgs->Args.s1.sema ==
.sema == ENDLIST)) {
ENDLIST)) waitTaskArgs->Args.s1.sema = A->Args.s1.sema;
waitTaskArgs->Args.s1.sema = }
A->Args.s1.sema; else {
else
signal_semaphore(1, S); signal_semaphore(1, S);
}
} }
_k_sem_group_wait(X); _k_sem_group_wait(X);
} else } else {
FREEARGS(X); /* ERROR */ FREEARGS(X); /* ERROR */
}
FREEARGS(A); FREEARGS(A);
return; return;
} else { } else {
@ -170,10 +177,12 @@ void _k_sem_group_wait_cancel(struct k_args *A)
} }
} }
A->Forw = X; A->Forw = X;
if (Y) if (Y) {
Y->Forw = A; Y->Forw = A;
else }
else {
S->Waiters = A; S->Waiters = A;
}
} }
/******************************************************************************* /*******************************************************************************
@ -195,14 +204,17 @@ void _k_sem_group_wait_accept(struct k_args *A)
while (X && (X->Prio <= A->Prio)) { while (X && (X->Prio <= A->Prio)) {
if (X->Ctxt.args == A->Ctxt.args) { if (X->Ctxt.args == A->Ctxt.args) {
if (Y) if (Y) {
Y->Forw = X->Forw; Y->Forw = X->Forw;
else }
else {
S->Waiters = X->Forw; S->Waiters = X->Forw;
}
if (X->Comm == WAITMRDY) { if (X->Comm == WAITMRDY) {
_k_sem_group_wait(X); _k_sem_group_wait(X);
} else } else {
FREEARGS(X); /* ERROR */ FREEARGS(X); /* ERROR */
}
FREEARGS(A); FREEARGS(A);
return; return;
} else { } else {
@ -225,8 +237,9 @@ void _k_sem_group_wait_timeout(struct k_args *A)
ksem_t *L; ksem_t *L;
#ifdef CONFIG_SYS_CLOCK_EXISTS #ifdef CONFIG_SYS_CLOCK_EXISTS
if (A->Time.timer) if (A->Time.timer) {
FREETIMER(A->Time.timer); FREETIMER(A->Time.timer);
}
#endif #endif
L = A->Args.s1.list; L = A->Args.s1.list;
@ -262,8 +275,9 @@ void _k_sem_group_ready(struct k_args *R)
A->Args.s1.sema = R->Args.s1.sema; A->Args.s1.sema = R->Args.s1.sema;
A->Comm = WAITMTMO; A->Comm = WAITMTMO;
#ifdef CONFIG_SYS_CLOCK_EXISTS #ifdef CONFIG_SYS_CLOCK_EXISTS
if (A->Time.timer) if (A->Time.timer) {
force_timeout(A); force_timeout(A);
}
else else
#endif #endif
_k_sem_group_wait_timeout(A); _k_sem_group_wait_timeout(A);
@ -281,15 +295,16 @@ void _k_sem_group_ready(struct k_args *R)
void _k_sem_wait_reply(struct k_args *A) void _k_sem_wait_reply(struct k_args *A)
{ {
#ifdef CONFIG_SYS_CLOCK_EXISTS #ifdef CONFIG_SYS_CLOCK_EXISTS
if (A->Time.timer) if (A->Time.timer) {
FREETIMER(A->Time.timer); FREETIMER(A->Time.timer);
}
if (A->Comm == WAITSTMO) { if (A->Comm == WAITSTMO) {
REMOVE_ELM(A); REMOVE_ELM(A);
A->Time.rcode = RC_TIME; A->Time.rcode = RC_TIME;
} else } else
#endif #endif
A->Time.rcode = RC_OK; A->Time.rcode = RC_OK;
reset_state_bit(A->Ctxt.proc, TF_SEMA); reset_state_bit(A->Ctxt.proc, TF_SEMA);
} }
/******************************************************************************* /*******************************************************************************
@ -308,14 +323,17 @@ void _k_sem_group_wait_request(struct k_args *A)
while (X && (X->Prio <= A->Prio)) { while (X && (X->Prio <= A->Prio)) {
if (X->Ctxt.args == A->Ctxt.args) { if (X->Ctxt.args == A->Ctxt.args) {
if (Y) if (Y) {
Y->Forw = X->Forw; Y->Forw = X->Forw;
else }
else {
S->Waiters = X->Forw; S->Waiters = X->Forw;
}
if (X->Comm == WAITMCAN) { if (X->Comm == WAITMCAN) {
_k_sem_group_wait(X); _k_sem_group_wait(X);
} else } else {
FREEARGS(X); /* ERROR */ FREEARGS(X); /* ERROR */
}
FREEARGS(A); FREEARGS(A);
return; return;
} else { } else {
@ -324,10 +342,12 @@ void _k_sem_group_wait_request(struct k_args *A)
} }
} }
A->Forw = X; A->Forw = X;
if (Y) if (Y) {
Y->Forw = A; Y->Forw = A;
else }
else {
S->Waiters = A; S->Waiters = A;
}
signal_semaphore(0, S); signal_semaphore(0, S);
} }
@ -349,8 +369,9 @@ void _k_sem_group_wait_any(struct k_args *A)
A->Args.s1.sema = ENDLIST; A->Args.s1.sema = ENDLIST;
A->Args.s1.nsem = 0; A->Args.s1.nsem = 0;
if (*L == ENDLIST) if (*L == ENDLIST) {
return; return;
}
while (*L != ENDLIST) { while (*L != ENDLIST) {
struct k_args *R; struct k_args *R;
@ -369,8 +390,9 @@ void _k_sem_group_wait_any(struct k_args *A)
#ifdef CONFIG_SYS_CLOCK_EXISTS #ifdef CONFIG_SYS_CLOCK_EXISTS
if (A->Time.ticks != TICKS_NONE) { if (A->Time.ticks != TICKS_NONE) {
if (A->Time.ticks == TICKS_UNLIMITED) if (A->Time.ticks == TICKS_UNLIMITED) {
A->Time.timer = NULL; A->Time.timer = NULL;
}
else { else {
A->Comm = WAITMTMO; A->Comm = WAITMTMO;
enlist_timeout(A); enlist_timeout(A);
@ -403,16 +425,18 @@ void _k_sem_wait_request(struct k_args *A)
set_state_bit(_k_current_task, TF_SEMA); set_state_bit(_k_current_task, TF_SEMA);
INSERT_ELM(S->Waiters, A); INSERT_ELM(S->Waiters, A);
#ifdef CONFIG_SYS_CLOCK_EXISTS #ifdef CONFIG_SYS_CLOCK_EXISTS
if (A->Time.ticks == TICKS_UNLIMITED) if (A->Time.ticks == TICKS_UNLIMITED) {
A->Time.timer = NULL; A->Time.timer = NULL;
}
else { else {
A->Comm = WAITSTMO; A->Comm = WAITSTMO;
enlist_timeout(A); enlist_timeout(A);
} }
#endif #endif
return; return;
} else } else {
A->Time.rcode = RC_FAIL; A->Time.rcode = RC_FAIL;
}
} }
/******************************************************************************* /*******************************************************************************
@ -422,12 +446,13 @@ void _k_sem_wait_request(struct k_args *A)
* This routine tests a semaphore to see if it has been signaled. If the signal * This routine tests a semaphore to see if it has been signaled. If the signal
* count is greater than zero, it is decremented. * count is greater than zero, it is decremented.
* *
* @param sema Semaphore to test.
* @param time Maximum number of ticks to wait.
*
* RETURNS: RC_OK, RC_FAIL, RC_TIME on success, failure, timeout respectively * RETURNS: RC_OK, RC_FAIL, RC_TIME on success, failure, timeout respectively
*/ */
int _task_sem_take(ksem_t sema, /* semaphore to test */ int _task_sem_take(ksem_t sema, int32_t time)
int32_t time /* maximum number of ticks to wait */
)
{ {
struct k_args A; struct k_args A;
@ -448,12 +473,13 @@ int _task_sem_take(ksem_t sema, /* semaphore to test */
* It returns the ID of the first semaphore in the group whose signal count is * It returns the ID of the first semaphore in the group whose signal count is
* greater than zero, and decrements the signal count. * greater than zero, and decrements the signal count.
* *
* @param group Group of semaphores to test.
* @param time Maximum number of ticks to wait.
*
* RETURNS: N/A * RETURNS: N/A
*/ */
ksem_t _task_sem_group_take(ksemg_t group, /* group of semaphores to test */ ksem_t _task_sem_group_take(ksemg_t group, int32_t time)
int32_t time /* maximum number of ticks to wait */
)
{ {
struct k_args A; struct k_args A;
@ -490,8 +516,9 @@ void _k_sem_group_signal(struct k_args *A)
{ {
ksem_t *L = A->Args.s1.list; ksem_t *L = A->Args.s1.list;
while ((A->Args.s1.sema = *L++) != ENDLIST) while ((A->Args.s1.sema = *L++) != ENDLIST) {
_k_sem_signal(A); _k_sem_signal(A);
}
} }
/******************************************************************************* /*******************************************************************************
@ -500,11 +527,12 @@ void _k_sem_group_signal(struct k_args *A)
* *
* This routine signals the specified semaphore. * This routine signals the specified semaphore.
* *
* @param sema Semaphore to signal.
*
* RETURNS: N/A * RETURNS: N/A
*/ */
void task_sem_give(ksem_t sema /* semaphore to signal */ void task_sem_give(ksem_t sema)
)
{ {
struct k_args A; struct k_args A;
@ -526,11 +554,12 @@ void task_sem_give(ksem_t sema /* semaphore to signal */
* Using task_sem_group_give() is faster than using multiple single signals, * Using task_sem_group_give() is faster than using multiple single signals,
* and ensures all signals take place before other tasks run. * and ensures all signals take place before other tasks run.
* *
* @param group Group of semaphores to signal.
*
* RETURNS: N/A * RETURNS: N/A
*/ */
void task_sem_group_give(ksemg_t group /* group of semaphores to signal */ void task_sem_group_give(ksemg_t group)
)
{ {
struct k_args A; struct k_args A;
@ -562,13 +591,13 @@ FUNC_ALIAS(isr_sem_give, fiber_sem_give, void);
* that is implicitly released once the command packet has been processed. * that is implicitly released once the command packet has been processed.
* To signal a semaphore from a task, task_sem_give() should be used instead. * To signal a semaphore from a task, task_sem_give() should be used instead.
* *
* @param sema Semaphore to signal.
* @param pSet Pointer to command packet set.
*
* RETURNS: N/A * RETURNS: N/A
*/ */
void isr_sem_give(ksem_t sema, /* semaphore to signal */ void isr_sem_give(ksem_t sema, struct cmd_pkt_set *pSet)
struct cmd_pkt_set *pSet /* ptr to command
packet set */
)
{ {
struct k_args *pCommand; /* ptr to command packet */ struct k_args *pCommand; /* ptr to command packet */
@ -610,8 +639,9 @@ void _k_sem_group_reset(struct k_args *A)
{ {
ksem_t *L = A->Args.s1.list; ksem_t *L = A->Args.s1.list;
while ((A->Args.s1.sema = *L++) != ENDLIST) while ((A->Args.s1.sema = *L++) != ENDLIST) {
_k_sem_reset(A); _k_sem_reset(A);
}
} }
/******************************************************************************* /*******************************************************************************
@ -620,11 +650,12 @@ void _k_sem_group_reset(struct k_args *A)
* *
* This routine resets the signal count of the specified semaphore to zero. * This routine resets the signal count of the specified semaphore to zero.
* *
* @param sema Semaphore to reset.
*
* RETURNS: N/A * RETURNS: N/A
*/ */
void task_sem_reset(ksem_t sema /* semaphore to reset */ void task_sem_reset(ksem_t sema)
)
{ {
struct k_args A; struct k_args A;
@ -641,11 +672,12 @@ void task_sem_reset(ksem_t sema /* semaphore to reset */
* group is an array of semaphore names terminated by the predefined constant * group is an array of semaphore names terminated by the predefined constant
* ENDLIST. * ENDLIST.
* *
* @param group Group of semaphores to reset.
*
* RETURNS: N/A * RETURNS: N/A
*/ */
void task_sem_group_reset(ksemg_t group /* group of semaphores to reset */ void task_sem_group_reset(ksemg_t group)
)
{ {
struct k_args A; struct k_args A;
@ -677,11 +709,12 @@ void _k_sem_inquiry(struct k_args *A)
* *
* This routine reads the signal count of the specified semaphore. * This routine reads the signal count of the specified semaphore.
* *
* @param sema Semaphore to query.
*
* RETURNS: signal count * RETURNS: signal count
*/ */
int task_sem_count_get(ksem_t sema /* semaphore to query */ int task_sem_count_get(ksem_t sema)
)
{ {
struct k_args A; struct k_args A;

View file

@ -98,12 +98,15 @@ void enlist_timer(struct k_timer *T)
if (P) { if (P) {
P->duration -= T->duration; P->duration -= T->duration;
P->Back = T; P->Back = T;
} else } else {
_k_timer_list_tail = T; _k_timer_list_tail = T;
if (Q) }
if (Q) {
Q->Forw = T; Q->Forw = T;
else }
else {
_k_timer_list_head = T; _k_timer_list_head = T;
}
T->Forw = P; T->Forw = P;
T->Back = Q; T->Back = Q;
} }
@ -239,12 +242,12 @@ void _k_timer_list_update(int ticks)
* This routine, called by K_swapper(), handles the request for allocating a * This routine, called by K_swapper(), handles the request for allocating a
* timer. * timer.
* *
* @param P Pointer to timer allocation request arguments.
*
* RETURNS: N/A * RETURNS: N/A
*/ */
void _k_timer_alloc( void _k_timer_alloc(struct k_args *P)
struct k_args *P /* pointer to timer allocation request arguments */
)
{ {
struct k_timer *T; struct k_timer *T;
struct k_args *A; struct k_args *A;
@ -309,11 +312,12 @@ void _k_timer_dealloc(struct k_args *P)
* This routine frees the resources associated with the timer. If a timer was * This routine frees the resources associated with the timer. If a timer was
* started, it has to be stopped using task_timer_stop() before it can be freed. * started, it has to be stopped using task_timer_stop() before it can be freed.
* *
* @param timer Timer to deallocate.
*
* RETURNS: N/A * RETURNS: N/A
*/ */
void task_timer_free(ktimer_t timer /* timer to deallocate */ void task_timer_free(ktimer_t timer)
)
{ {
struct k_args A; struct k_args A;
@ -329,25 +333,26 @@ void task_timer_free(ktimer_t timer /* timer to deallocate */
* This routine, called by K_swapper(), handles the start timer request from * This routine, called by K_swapper(), handles the start timer request from
* both task_timer_start() and task_timer_restart(). * both task_timer_start() and task_timer_restart().
* *
* @param P Pointer to timer start request arguments.
*
* RETURNS: N/A * RETURNS: N/A
*/ */
void _k_timer_start(struct k_args *P /* pointer to timer start void _k_timer_start(struct k_args *P)
request arguments */
)
{ {
struct k_timer *T = P->Args.c1.timer; /* ptr to the timer to start */ struct k_timer *T = P->Args.c1.timer; /* ptr to the timer to start */
if (T->duration != -1) /* Stop the timer if it is active */ if (T->duration != -1) { /* Stop the timer if it is active */
delist_timer(T); delist_timer(T);
}
T->duration = (int32_t)P->Args.c1.time1; /* Set the initial delay */ T->duration = (int32_t)P->Args.c1.time1; /* Set the initial delay */
T->period = P->Args.c1.time2; /* Set the period */ T->period = P->Args.c1.time2; /* Set the period */
/* /*
* Either the initial delay and/or the period is invalid. Mark * Either the initial delay and/or the period is invalid. Mark
* the timer as inactive. * the timer as inactive.
*/ */
if ((T->duration < 0) || (T->period < 0)) { if ((T->duration < 0) || (T->period < 0)) {
T->duration = -1; T->duration = -1;
return; return;
@ -362,9 +367,8 @@ void _k_timer_start(struct k_args *P /* pointer to timer start
} }
} }
if (P->Args.c1.sema != ENDLIST) { /* Track the semaphore to /* Track the semaphore to signal for when the timer expires. */
* signal for when the timer if (P->Args.c1.sema != ENDLIST) {
* expires. */
T->Args->Comm = SIGNALS; T->Args->Comm = SIGNALS;
T->Args->Args.s1.sema = P->Args.c1.sema; T->Args->Args.s1.sema = P->Args.c1.sema;
} }
@ -388,14 +392,16 @@ void _k_timer_start(struct k_args *P /* pointer to timer start
* task_timer_stop(): if the allocated timer was still running (from a * task_timer_stop(): if the allocated timer was still running (from a
* previous call), it will be cancelled; if not, nothing will happen. * previous call), it will be cancelled; if not, nothing will happen.
* *
* @param timer Timer to start.
* @param duration Initial delay in ticks.
* @param period Repetition interval in ticks.
* @param sema Semaphore to signal.
*
* RETURNS: N/A * RETURNS: N/A
*/ */
void task_timer_start(ktimer_t timer, /* timer to start */ void task_timer_start(ktimer_t timer, int32_t duration, int32_t period,
int32_t duration, /* initial delay in ticks */ ksem_t sema)
int32_t period, /* repetition interval in ticks */
ksem_t sema /* semaphore to signal */
)
{ {
struct k_args A; struct k_args A;
@ -413,13 +419,14 @@ void task_timer_start(ktimer_t timer, /* timer to start */
* *
* This routine restarts the timer specified by <timer>. * This routine restarts the timer specified by <timer>.
* *
* @param timer Timer to restart.
* @param duration Initial delay.
* @param period Repetition interval.
*
* RETURNS: N/A * RETURNS: N/A
*/ */
void task_timer_restart(ktimer_t timer, /* timer to restart */ void task_timer_restart(ktimer_t timer, int32_t duration, int32_t period)
int32_t duration, /* initial delay */
int32_t period /* repetition interval */
)
{ {
struct k_args A; struct k_args A;
@ -456,11 +463,12 @@ void _k_timer_stop(struct k_args *P)
* This routine stops the specified timer. If the timer period has already * This routine stops the specified timer. If the timer period has already
* elapsed, the call has no effect. * elapsed, the call has no effect.
* *
* @param timer Timer to stop.
*
* RETURNS: N/A * RETURNS: N/A
*/ */
void task_timer_stop(ktimer_t timer /* timer to stop */ void task_timer_stop(ktimer_t timer)
)
{ {
struct k_args A; struct k_args A;
@ -505,8 +513,9 @@ void _k_task_sleep(struct k_args *P)
{ {
struct k_timer *T; struct k_timer *T;
if ((P->Time.ticks) <= 0) if ((P->Time.ticks) <= 0) {
return; return;
}
GETTIMER(T); GETTIMER(T);
T->duration = P->Time.ticks; T->duration = P->Time.ticks;
@ -529,11 +538,12 @@ void _k_task_sleep(struct k_args *P)
* ticks. When the task is awakened, it is rescheduled according to its * ticks. When the task is awakened, it is rescheduled according to its
* priority. * priority.
* *
* @param ticks Number of ticks for which to sleep.
*
* RETURNS: N/A * RETURNS: N/A
*/ */
void task_sleep(int32_t ticks /* number of ticks for which to sleep */ void task_sleep(int32_t ticks)
)
{ {
struct k_args A; struct k_args A;

View file

@ -69,13 +69,17 @@ void _k_task_monitor(struct k_proc *X, uint32_t D)
if (++K_monitor_wind == k_monitor_capacity) { if (++K_monitor_wind == k_monitor_capacity) {
K_monitor_wind = 0; K_monitor_wind = 0;
k_monitor_wptr = k_monitor_buff; k_monitor_wptr = k_monitor_buff;
} else }
else {
++k_monitor_wptr; ++k_monitor_wptr;
if (k_monitor_nrec < k_monitor_capacity) }
if (k_monitor_nrec < k_monitor_capacity) {
k_monitor_nrec++; k_monitor_nrec++;
}
} }
if ((_k_task_switch_callback != NULL) && (D == 0)) if ((_k_task_switch_callback != NULL) && (D == 0)) {
(_k_task_switch_callback)(X->Ident, timer_read()); (_k_task_switch_callback)(X->Ident, timer_read());
}
} }
void _k_task_monitor_args(struct k_args *A) void _k_task_monitor_args(struct k_args *A)
@ -97,11 +101,14 @@ void _k_task_monitor_args(struct k_args *A)
if (++K_monitor_wind == k_monitor_capacity) { if (++K_monitor_wind == k_monitor_capacity) {
K_monitor_wind = 0; K_monitor_wind = 0;
k_monitor_wptr = k_monitor_buff; k_monitor_wptr = k_monitor_buff;
} else }
else {
++k_monitor_wptr; ++k_monitor_wptr;
}
if (k_monitor_nrec < k_monitor_capacity) if (k_monitor_nrec < k_monitor_capacity) {
k_monitor_nrec++; k_monitor_nrec++;
}
} }
} }
@ -110,8 +117,9 @@ void _k_task_monitor_read(struct k_args *A)
A->Args.z4.nrec = k_monitor_nrec; A->Args.z4.nrec = k_monitor_nrec;
if (A->Args.z4.rind < k_monitor_nrec) { if (A->Args.z4.rind < k_monitor_nrec) {
int i = K_monitor_wind - k_monitor_nrec + A->Args.z4.rind; int i = K_monitor_wind - k_monitor_nrec + A->Args.z4.rind;
if (i < 0) if (i < 0) {
i += k_monitor_capacity; i += k_monitor_capacity;
}
A->Args.z4.mrec = k_monitor_buff[i]; A->Args.z4.mrec = k_monitor_buff[i];
} }
} }

View file

@ -97,8 +97,9 @@ size_t __strlen_s(const char *str, size_t maxElem)
{ {
size_t len = 0; /* the calculated string length */ size_t len = 0; /* the calculated string length */
if (str == NULL) if (str == NULL) {
return 0; return 0;
}
while ((len < maxElem) && (str[len] != '\0')) { while ((len < maxElem) && (str[len] != '\0')) {
len++; len++;
@ -145,12 +146,12 @@ errno_t __strcpy_s(char *dest, size_t nDestElem, const char *src)
_NanoFatalErrorHandler(_NANO_ERR_INVALID_STRING_OP, &_default_esf); _NanoFatalErrorHandler(_NANO_ERR_INVALID_STRING_OP, &_default_esf);
/* /*
* the following statement is included in case the compiler * the following statement is included in case the compiler
* doesn't recognize that _NanoFatalErrorHandler() never returns * doesn't recognize that _NanoFatalErrorHandler() never returns
* and complains about "missing return value for non-void function" * and complains about "missing return value for non-void function"
* (should be optimized away if compiler recognizes the non-return) * (should be optimized away if compiler recognizes the non-return)
*/ */
return 1; return 1;
} }

View file

@ -54,9 +54,9 @@ static int driver_send(struct bt_buf *buf)
} }
static struct bt_driver drv = { static struct bt_driver drv = {
.head_reserve = 0, .head_reserve = 0,
.open = driver_open, .open = driver_open,
.send = driver_send, .send = driver_send,
}; };
static void driver_init(void) static void driver_init(void)
@ -75,13 +75,15 @@ void main(void)
driver_init(); driver_init();
ret = bt_init(); ret = bt_init();
if (ret == EXPECTED_ERROR) if (ret == EXPECTED_ERROR) {
ret_code = TC_PASS; ret_code = TC_PASS;
else }
else {
ret_code = TC_FAIL; ret_code = TC_FAIL;
}
TC_END(ret_code, "%s - %s.\n", ret_code == TC_PASS ? PASS : FAIL, TC_END(ret_code, "%s - %s.\n", ret_code == TC_PASS ? PASS : FAIL,
__func__); __func__);
TC_END_REPORT(ret_code); TC_END_REPORT(ret_code);
} }

View file

@ -96,15 +96,15 @@ static char sw_isr_trigger_1[] = {
#if defined(CONFIG_CPU_CORTEXM) #if defined(CONFIG_CPU_CORTEXM)
#include <nanokernel.h> #include <nanokernel.h>
static inline void sw_isr_trigger_0(void) static inline void sw_isr_trigger_0(void)
{ {
_NvicSwInterruptTrigger(0); _NvicSwInterruptTrigger(0);
} }
#if NUM_SW_IRQS >= 2 #if NUM_SW_IRQS >= 2
static inline void sw_isr_trigger_1(void) static inline void sw_isr_trigger_1(void)
{ {
_NvicSwInterruptTrigger(1); _NvicSwInterruptTrigger(1);
} }
#endif /* NUM_SW_IRQS >= 2 */ #endif /* NUM_SW_IRQS >= 2 */
#endif /* CONFIG_CPU_CORTEXM */ #endif /* CONFIG_CPU_CORTEXM */
#endif #endif
@ -112,7 +112,7 @@ static inline void sw_isr_trigger_1(void)
struct isrInitInfo { struct isrInitInfo {
vvpfn isr[2]; vvpfn isr[2];
void *arg[2]; void *arg[2];
}; };
/******************************************************************************* /*******************************************************************************
* *
@ -120,47 +120,44 @@ struct isrInitInfo {
* *
*/ */
static int initIRQ static int initIRQ(struct isrInitInfo *i)
( {
struct isrInitInfo *i
)
{
#if defined(VXMICRO_ARCH_x86) #if defined(VXMICRO_ARCH_x86)
int vector; /* vector to which interrupt is connected */ int vector; /* vector to which interrupt is connected */
if (i->isr[0]) { if (i->isr[0]) {
vector = irq_connect(NANO_SOFT_IRQ, IRQ_PRIORITY, i->isr[0], vector = irq_connect(NANO_SOFT_IRQ, IRQ_PRIORITY, i->isr[0],
i->arg[0], nanoIntStub1); i->arg[0], nanoIntStub1);
if (-1 == vector) { if (-1 == vector) {
return -1; return -1;
} }
sw_isr_trigger_0[1] = vector; sw_isr_trigger_0[1] = vector;
} }
#if NUM_SW_IRQS >= 2 #if NUM_SW_IRQS >= 2
if (i->isr[1]) { if (i->isr[1]) {
vector = irq_connect(NANO_SOFT_IRQ, IRQ_PRIORITY, i->isr[1], vector = irq_connect(NANO_SOFT_IRQ, IRQ_PRIORITY, i->isr[1],
i->arg[1], nanoIntStub2); i->arg[1], nanoIntStub2);
if (-1 == vector) { if (-1 == vector) {
return -1; return -1;
} }
sw_isr_trigger_1[1] = vector; sw_isr_trigger_1[1] = vector;
} }
#endif /* NUM_SW_IRQS >= 2 */ #endif /* NUM_SW_IRQS >= 2 */
#elif defined(VXMICRO_ARCH_arm) #elif defined(VXMICRO_ARCH_arm)
#if defined(CONFIG_CPU_CORTEXM) #if defined(CONFIG_CPU_CORTEXM)
if (i->isr[0]) { if (i->isr[0]) {
(void) irq_connect(0, IRQ_PRIORITY, i->isr[0], i->arg[0]); (void) irq_connect(0, IRQ_PRIORITY, i->isr[0], i->arg[0]);
irq_enable(0); irq_enable(0);
} }
if (i->isr[1]) { if (i->isr[1]) {
(void) irq_connect(1, IRQ_PRIORITY, i->isr[1], i->arg[1]); (void) irq_connect(1, IRQ_PRIORITY, i->isr[1], i->arg[1]);
irq_enable(1); irq_enable(1);
} }
#endif /* CONFIG_CPU_CORTEXM */ #endif /* CONFIG_CPU_CORTEXM */
#endif /* VXMICRO_ARCH_x86 */ #endif /* VXMICRO_ARCH_x86 */
return 0; return 0;
} }
#endif /* _IRQ_TEST_COMMON__H_ */ #endif /* _IRQ_TEST_COMMON__H_ */

View file

@ -63,29 +63,29 @@
void helloLoop(const char *taskname, ksem_t mySem, ksem_t otherSem) void helloLoop(const char *taskname, ksem_t mySem, ksem_t otherSem)
{ {
while (1) { while (1) {
task_sem_take_wait(mySem); task_sem_take_wait(mySem);
/* say "hello" */ /* say "hello" */
PRINT("%s: Hello World!\n", taskname); PRINT("%s: Hello World!\n", taskname);
/* wait a while, then let other task have a turn */ /* wait a while, then let other task have a turn */
task_sleep(SLEEPTICKS); task_sleep(SLEEPTICKS);
task_sem_give(otherSem); task_sem_give(otherSem);
} }
} }
void taskA(void) void taskA(void)
{ {
/* taskA gives its own semaphore, allowing it to say hello right away */ /* taskA gives its own semaphore, allowing it to say hello right away */
task_sem_give(TASKASEM); task_sem_give(TASKASEM);
/* invoke routine that allows task to ping-pong hello messages with taskB */ /* invoke routine that allows task to ping-pong hello messages with taskB */
helloLoop(__FUNCTION__, TASKASEM, TASKBSEM); helloLoop(__FUNCTION__, TASKASEM, TASKBSEM);
} }
void taskB(void) void taskB(void)
{ {
/* invoke routine that allows task to ping-pong hello messages with taskA */ /* invoke routine that allows task to ping-pong hello messages with taskA */
helloLoop(__FUNCTION__, TASKBSEM, TASKASEM); helloLoop(__FUNCTION__, TASKBSEM, TASKASEM);
} }
@ -121,16 +121,16 @@ void fiberEntry(void)
nano_timer_init(&timer, data); nano_timer_init(&timer, data);
while (1) { while (1) {
/* wait for task to let us have a turn */ /* wait for task to let us have a turn */
nano_fiber_sem_take_wait(&nanoSemFiber); nano_fiber_sem_take_wait(&nanoSemFiber);
/* say "hello" */ /* say "hello" */
PRINT("%s: Hello World!\n", __FUNCTION__); PRINT("%s: Hello World!\n", __FUNCTION__);
/* wait a while, then let task have a turn */ /* wait a while, then let task have a turn */
nano_fiber_timer_start(&timer, SLEEPTICKS); nano_fiber_timer_start(&timer, SLEEPTICKS);
nano_fiber_timer_wait(&timer); nano_fiber_timer_wait(&timer);
nano_fiber_sem_give(&nanoSemTask); nano_fiber_sem_give(&nanoSemTask);
} }
} }
@ -146,16 +146,16 @@ void main(void)
nano_timer_init(&timer, data); nano_timer_init(&timer, data);
while (1) { while (1) {
/* say "hello" */ /* say "hello" */
PRINT("%s: Hello World!\n", __FUNCTION__); PRINT("%s: Hello World!\n", __FUNCTION__);
/* wait a while, then let fiber have a turn */ /* wait a while, then let fiber have a turn */
nano_task_timer_start(&timer, SLEEPTICKS); nano_task_timer_start(&timer, SLEEPTICKS);
nano_task_timer_wait(&timer); nano_task_timer_wait(&timer);
nano_task_sem_give(&nanoSemFiber); nano_task_sem_give(&nanoSemFiber);
/* now wait for fiber to let us have a turn */ /* now wait for fiber to let us have a turn */
nano_task_sem_take_wait(&nanoSemTask); nano_task_sem_take_wait(&nanoSemTask);
} }
} }

View file

@ -71,30 +71,28 @@ kmutex_t forks[] = {forkMutex0, forkMutex1, forkMutex2, forkMutex3, forkMutex4,
* *
* myPrint - print a philosophers state * myPrint - print a philosophers state
* *
* @param id Philosopher ID.
* @param str EATING or THINKING.
*
* RETURNS: N/A * RETURNS: N/A
*/ */
static void myPrint static void myPrint(int id, char *str)
( {
int id, /* philosopher ID */
char *str /* EATING or THINKING */
)
{
PRINTF("\x1b[%d;%dHPhilosopher %d %s\n", id + 1, 1, id, str); PRINTF("\x1b[%d;%dHPhilosopher %d %s\n", id + 1, 1, id, str);
} }
/******************************************************************************* /*******************************************************************************
* *
* myDelay - wait for a number of ticks to elapse * myDelay - wait for a number of ticks to elapse
* *
* @param ticks Number of ticks to delay.
*
* RETURNS: N/A * RETURNS: N/A
*/ */
static void myDelay static void myDelay(int ticks)
( {
int ticks /* # of ticks to delay */
)
{
#ifdef CONFIG_MICROKERNEL #ifdef CONFIG_MICROKERNEL
task_sleep(ticks); task_sleep(ticks);
#else #else
@ -104,7 +102,7 @@ static void myDelay
nano_fiber_timer_start(&timer, ticks); nano_fiber_timer_start(&timer, ticks);
nano_fiber_timer_wait(&timer); nano_fiber_timer_wait(&timer);
#endif #endif
} }
/******************************************************************************* /*******************************************************************************
* *
@ -117,7 +115,7 @@ static void myDelay
*/ */
void philEntry(void) void philEntry(void)
{ {
#ifdef CONFIG_NANOKERNEL #ifdef CONFIG_NANOKERNEL
struct nano_sem *f1; /* fork #1 */ struct nano_sem *f1; /* fork #1 */
struct nano_sem *f2; /* fork #2 */ struct nano_sem *f2; /* fork #2 */
@ -125,33 +123,33 @@ void philEntry(void)
kmutex_t f1; /* fork #1 */ kmutex_t f1; /* fork #1 */
kmutex_t f2; /* fork #2 */ kmutex_t f2; /* fork #2 */
#endif #endif
static int myId; /* next philosopher ID */ static int myId; /* next philosopher ID */
int pri = irq_lock(); /* interrupt lock level */ int pri = irq_lock(); /* interrupt lock level */
int id = myId++; /* current philosopher ID */ int id = myId++; /* current philosopher ID */
irq_unlock(pri); irq_unlock(pri);
/* always take the lowest fork first */ /* always take the lowest fork first */
if ((id+1) != N_PHILOSOPHERS) { if ((id+1) != N_PHILOSOPHERS) {
f1 = FORK(id); f1 = FORK(id);
f2 = FORK(id + 1); f2 = FORK(id + 1);
} }
else { else {
f1 = FORK(0); f1 = FORK(0);
f2 = FORK(id); f2 = FORK(id);
} }
while (1) { while (1) {
TAKE(f1); TAKE(f1);
TAKE(f2); TAKE(f2);
PRINT(id, "EATING "); PRINT(id, "EATING ");
RANDDELAY(id); RANDDELAY(id);
GIVE(f2); GIVE(f2);
GIVE(f1); GIVE(f1);
PRINT(id, "THINKING"); PRINT(id, "THINKING");
RANDDELAY(id); RANDDELAY(id);
}
} }
}

View file

@ -74,27 +74,28 @@ struct nano_sem forks[N_PHILOSOPHERS];
*/ */
int main(void) int main(void)
{ {
int i; int i;
PRINTF(DEMO_DESCRIPTION, "fibers", "nanokernel"); PRINTF(DEMO_DESCRIPTION, "fibers", "nanokernel");
for (i = 0; i < N_PHILOSOPHERS; i++) { for (i = 0; i < N_PHILOSOPHERS; i++) {
nano_sem_init(&forks[i]); nano_sem_init(&forks[i]);
nano_task_sem_give(&forks[i]); nano_task_sem_give(&forks[i]);
} }
/* create philosopher fibers */ /* create philosopher fibers */
for (i = 0; i < N_PHILOSOPHERS; i++) for (i = 0; i < N_PHILOSOPHERS; i++) {
task_fiber_start(&philStack[i][0], STSIZE, task_fiber_start(&philStack[i][0], STSIZE,
(nano_fiber_entry_t) philEntry, 0, 0, 6, 0); (nano_fiber_entry_t) philEntry, 0, 0, 6, 0);
}
/* wait forever */ /* wait forever */
while (1) { while (1) {
extern void nano_cpu_idle(void); extern void nano_cpu_idle(void);
nano_cpu_idle(); nano_cpu_idle();
}
} }
}
#else #else
/******************************************************************************* /*******************************************************************************
@ -105,14 +106,14 @@ int main(void)
*/ */
void philDemo(void) void philDemo(void)
{ {
PRINTF(DEMO_DESCRIPTION, "tasks", "microkernel"); PRINTF(DEMO_DESCRIPTION, "tasks", "microkernel");
task_group_start(PHI); task_group_start(PHI);
/* wait forever */ /* wait forever */
while (1) { while (1) {
task_sleep(10000); task_sleep(10000);
}
} }
}
#endif #endif

View file

@ -66,7 +66,7 @@ int example_handler (int event);
*/ */
void event_test(void) void event_test(void)
{ {
int nReturn; int nReturn;
int nCounter; int nCounter;
uint32_t et; /* elapsed time */ uint32_t et; /* elapsed time */
@ -74,107 +74,107 @@ void event_test(void)
PRINT_STRING(dashline, output_file); PRINT_STRING(dashline, output_file);
et = BENCH_START(); et = BENCH_START();
for (nCounter = 0; nCounter < NR_OF_EVENT_RUNS; nCounter++) { for (nCounter = 0; nCounter < NR_OF_EVENT_RUNS; nCounter++) {
nReturn = task_event_send(TEST_EVENT); nReturn = task_event_send(TEST_EVENT);
#ifdef EVENT_CHECK #ifdef EVENT_CHECK
if (nReturn != RC_OK) { if (nReturn != RC_OK) {
PRINT_STRING(EventSignalErr, output_file); PRINT_STRING(EventSignalErr, output_file);
return; /* error */ return; /* error */
} }
#endif /* EVENT_CHECK */ #endif /* EVENT_CHECK */
} }
et = TIME_STAMP_DELTA_GET(et); et = TIME_STAMP_DELTA_GET(et);
check_result(); check_result();
PRINT_F(output_file, FORMAT, "Signal enabled event", PRINT_F(output_file, FORMAT, "Signal enabled event",
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_EVENT_RUNS)); SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_EVENT_RUNS));
et = BENCH_START(); et = BENCH_START();
for (nCounter = 0; nCounter < NR_OF_EVENT_RUNS; nCounter++) { for (nCounter = 0; nCounter < NR_OF_EVENT_RUNS; nCounter++) {
nReturn = task_event_send(TEST_EVENT); nReturn = task_event_send(TEST_EVENT);
#ifdef EVENT_CHECK #ifdef EVENT_CHECK
if (nReturn != RC_OK) { if (nReturn != RC_OK) {
PRINT_STRING(EventSignalErr, output_file); PRINT_STRING(EventSignalErr, output_file);
task_sleep(SLEEP_TIME); task_sleep(SLEEP_TIME);
return; /* error */ return; /* error */
} }
#endif /* EVENT_CHECK */ #endif /* EVENT_CHECK */
nReturn = task_event_recv(TEST_EVENT); nReturn = task_event_recv(TEST_EVENT);
#ifdef EVENT_CHECK #ifdef EVENT_CHECK
if (nReturn != RC_OK) { if (nReturn != RC_OK) {
PRINT_STRING(EventTestErr, output_file); PRINT_STRING(EventTestErr, output_file);
task_sleep(SLEEP_TIME); task_sleep(SLEEP_TIME);
return; /* error */ return; /* error */
} }
#endif /* EVENT_CHECK */ #endif /* EVENT_CHECK */
} }
et = TIME_STAMP_DELTA_GET(et); et = TIME_STAMP_DELTA_GET(et);
check_result(); check_result();
PRINT_F(output_file, FORMAT, "Signal event & Test event", PRINT_F(output_file, FORMAT, "Signal event & Test event",
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_EVENT_RUNS)); SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_EVENT_RUNS));
et = BENCH_START(); et = BENCH_START();
for (nCounter = 0; nCounter < NR_OF_EVENT_RUNS; nCounter++) { for (nCounter = 0; nCounter < NR_OF_EVENT_RUNS; nCounter++) {
nReturn = task_event_send(TEST_EVENT); nReturn = task_event_send(TEST_EVENT);
#ifdef EVENT_CHECK #ifdef EVENT_CHECK
if (nReturn != RC_OK) { if (nReturn != RC_OK) {
PRINT_STRING(EventSignalErr, output_file); PRINT_STRING(EventSignalErr, output_file);
return; /* error */ return; /* error */
} }
#endif /* EVENT_CHECK */ #endif /* EVENT_CHECK */
nReturn = task_event_recv_wait(TEST_EVENT); nReturn = task_event_recv_wait(TEST_EVENT);
#ifdef EVENT_CHECK #ifdef EVENT_CHECK
if (nReturn != RC_OK) { if (nReturn != RC_OK) {
PRINT_STRING(EventTestErr, output_file); PRINT_STRING(EventTestErr, output_file);
return; /* error */ return; /* error */
} }
#endif /* EVENT_CHECK */ #endif /* EVENT_CHECK */
} }
et = TIME_STAMP_DELTA_GET(et); et = TIME_STAMP_DELTA_GET(et);
check_result(); check_result();
PRINT_F(output_file, FORMAT, "Signal event & TestW event", PRINT_F(output_file, FORMAT, "Signal event & TestW event",
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_EVENT_RUNS)); SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_EVENT_RUNS));
PRINT_STRING("| Signal event with installed handler" PRINT_STRING("| Signal event with installed handler"
" |\n", output_file); " |\n", output_file);
nReturn = task_event_set_handler (TEST_EVENT, example_handler); nReturn = task_event_set_handler (TEST_EVENT, example_handler);
if (nReturn != RC_OK) { if (nReturn != RC_OK) {
PRINT_F(output_file, "-------- Error installing event handler.\n"); PRINT_F(output_file, "-------- Error installing event handler.\n");
task_sleep(SLEEP_TIME); task_sleep(SLEEP_TIME);
return; /* error */ return; /* error */
} }
for (nCounter = 0; nCounter < NR_OF_EVENT_RUNS; nCounter++) { for (nCounter = 0; nCounter < NR_OF_EVENT_RUNS; nCounter++) {
nReturn = task_event_send(TEST_EVENT); nReturn = task_event_send(TEST_EVENT);
#ifdef EVENT_CHECK #ifdef EVENT_CHECK
if (nReturn != RC_OK) { if (nReturn != RC_OK) {
PRINT_STRING(EventSignalErr, output_file); PRINT_STRING(EventSignalErr, output_file);
task_sleep(SLEEP_TIME); task_sleep(SLEEP_TIME);
return; /* error */ return; /* error */
} }
if (nEventValue != TEST_EVENT + 1) { if (nEventValue != TEST_EVENT + 1) {
PRINT_STRING(EventHandlerErr, output_file); PRINT_STRING(EventHandlerErr, output_file);
task_sleep(SLEEP_TIME); task_sleep(SLEEP_TIME);
return; /* error */ return; /* error */
} }
#endif /* EVENT_CHECK */ #endif /* EVENT_CHECK */
nEventValue = 0; nEventValue = 0;
} }
nReturn = task_event_set_handler (TEST_EVENT, NULL); nReturn = task_event_set_handler (TEST_EVENT, NULL);
if (nReturn != RC_OK) { if (nReturn != RC_OK) {
PRINT_F(output_file, "Error removing event handler.\n"); PRINT_F(output_file, "Error removing event handler.\n");
task_sleep(SLEEP_TIME); task_sleep(SLEEP_TIME);
return; /* error */ return; /* error */
} }
PRINT_STRING("| Handler responds OK" PRINT_STRING("| Handler responds OK"
" |\n", " |\n",
output_file); output_file);
return; /* success */ return; /* success */
} }
/******************************************************************************* /*******************************************************************************
@ -190,10 +190,10 @@ void event_test(void)
*/ */
int example_handler (int event) int example_handler (int event)
{ {
nEventValue = event + 1; nEventValue = event + 1;
return 1; return 1;
} }
#endif /* EVENT_BENCH */ #endif /* EVENT_BENCH */

View file

@ -44,73 +44,73 @@
*/ */
void queue_test(void) void queue_test(void)
{ {
uint32_t et; /* elapsed time */ uint32_t et; /* elapsed time */
int i; int i;
PRINT_STRING(dashline, output_file); PRINT_STRING(dashline, output_file);
et = BENCH_START(); et = BENCH_START();
for (i = 0; i < NR_OF_FIFO_RUNS; i++) { for (i = 0; i < NR_OF_FIFO_RUNS; i++) {
task_fifo_put_wait(DEMOQX1, data_bench); task_fifo_put_wait(DEMOQX1, data_bench);
} }
et = TIME_STAMP_DELTA_GET(et); et = TIME_STAMP_DELTA_GET(et);
PRINT_F(output_file, FORMAT, "enqueue 1 byte msg in FIFO", PRINT_F(output_file, FORMAT, "enqueue 1 byte msg in FIFO",
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_FIFO_RUNS)); SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_FIFO_RUNS));
et = BENCH_START(); et = BENCH_START();
for (i = 0; i < NR_OF_FIFO_RUNS; i++) { for (i = 0; i < NR_OF_FIFO_RUNS; i++) {
task_fifo_get_wait(DEMOQX1, data_bench); task_fifo_get_wait(DEMOQX1, data_bench);
} }
et = TIME_STAMP_DELTA_GET(et); et = TIME_STAMP_DELTA_GET(et);
check_result(); check_result();
PRINT_F(output_file, FORMAT, "dequeue 1 byte msg in FIFO", PRINT_F(output_file, FORMAT, "dequeue 1 byte msg in FIFO",
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_FIFO_RUNS)); SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_FIFO_RUNS));
et = BENCH_START(); et = BENCH_START();
for (i = 0; i < NR_OF_FIFO_RUNS; i++) { for (i = 0; i < NR_OF_FIFO_RUNS; i++) {
task_fifo_put_wait(DEMOQX4, data_bench); task_fifo_put_wait(DEMOQX4, data_bench);
} }
et = TIME_STAMP_DELTA_GET(et); et = TIME_STAMP_DELTA_GET(et);
check_result(); check_result();
PRINT_F(output_file, FORMAT, "enqueue 4 bytes msg in FIFO", PRINT_F(output_file, FORMAT, "enqueue 4 bytes msg in FIFO",
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_FIFO_RUNS)); SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_FIFO_RUNS));
et = BENCH_START(); et = BENCH_START();
for (i = 0; i < NR_OF_FIFO_RUNS; i++) { for (i = 0; i < NR_OF_FIFO_RUNS; i++) {
task_fifo_get_wait(DEMOQX4, data_bench); task_fifo_get_wait(DEMOQX4, data_bench);
} }
et = TIME_STAMP_DELTA_GET(et); et = TIME_STAMP_DELTA_GET(et);
check_result(); check_result();
PRINT_F(output_file, FORMAT, "dequeue 4 bytes msg in FIFO", PRINT_F(output_file, FORMAT, "dequeue 4 bytes msg in FIFO",
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_FIFO_RUNS)); SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_FIFO_RUNS));
task_sem_give(STARTRCV); task_sem_give(STARTRCV);
et = BENCH_START(); et = BENCH_START();
for (i = 0; i < NR_OF_FIFO_RUNS; i++) { for (i = 0; i < NR_OF_FIFO_RUNS; i++) {
task_fifo_put_wait(DEMOQX1, data_bench); task_fifo_put_wait(DEMOQX1, data_bench);
} }
et = TIME_STAMP_DELTA_GET(et); et = TIME_STAMP_DELTA_GET(et);
check_result(); check_result();
PRINT_F(output_file, FORMAT, PRINT_F(output_file, FORMAT,
"enqueue 1 byte msg in FIFO to a waiting higher priority task", "enqueue 1 byte msg in FIFO to a waiting higher priority task",
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_FIFO_RUNS)); SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_FIFO_RUNS));
et = BENCH_START(); et = BENCH_START();
for (i = 0; i < NR_OF_FIFO_RUNS; i++) { for (i = 0; i < NR_OF_FIFO_RUNS; i++) {
task_fifo_put_wait(DEMOQX4, data_bench); task_fifo_put_wait(DEMOQX4, data_bench);
} }
et = TIME_STAMP_DELTA_GET(et); et = TIME_STAMP_DELTA_GET(et);
check_result(); check_result();
PRINT_F(output_file, FORMAT, PRINT_F(output_file, FORMAT,
"enqueue 4 bytes in FIFO to a waiting higher priority task", "enqueue 4 bytes in FIFO to a waiting higher priority task",
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_FIFO_RUNS)); SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_FIFO_RUNS));
} }
#endif /* FIFO_BENCH */ #endif /* FIFO_BENCH */

View file

@ -46,16 +46,16 @@
*/ */
void dequtask(void) void dequtask(void)
{ {
int x, i; int x, i;
for (i = 0; i < NR_OF_FIFO_RUNS; i++) { for (i = 0; i < NR_OF_FIFO_RUNS; i++) {
task_fifo_get_wait(DEMOQX1, &x); task_fifo_get_wait(DEMOQX1, &x);
} }
for (i = 0; i < NR_OF_FIFO_RUNS; i++) { for (i = 0; i < NR_OF_FIFO_RUNS; i++) {
task_fifo_get_wait(DEMOQX4, &x); task_fifo_get_wait(DEMOQX4, &x);
}
} }
}
#endif /* FIFO_BENCH */ #endif /* FIFO_BENCH */

View file

@ -100,7 +100,7 @@ void mailbox_put(uint32_t size, int count, uint32_t *time);
*/ */
void mailbox_test(void) void mailbox_test(void)
{ {
uint32_t putsize; uint32_t putsize;
uint32_t puttime; uint32_t puttime;
int putcount; int putcount;
@ -109,14 +109,14 @@ void mailbox_test(void)
PRINT_STRING(dashline, output_file); PRINT_STRING(dashline, output_file);
PRINT_STRING("| " PRINT_STRING("| "
"M A I L B O X M E A S U R E M E N T S" "M A I L B O X M E A S U R E M E N T S"
" |\n", output_file); " |\n", output_file);
PRINT_STRING(dashline, output_file); PRINT_STRING(dashline, output_file);
PRINT_STRING("| Send mailbox message to waiting high " PRINT_STRING("| Send mailbox message to waiting high "
"priority task and wait |\n", output_file); "priority task and wait |\n", output_file);
PRINT_F(output_file, "| repeat for %4d times and take the " PRINT_F(output_file, "| repeat for %4d times and take the "
"average |\n", "average |\n",
NR_OF_MBOX_RUNS); NR_OF_MBOX_RUNS);
PRINT_STRING(dashline, output_file); PRINT_STRING(dashline, output_file);
PRINT_HEADER(); PRINT_HEADER();
PRINT_STRING(dashline, output_file); PRINT_STRING(dashline, output_file);
@ -131,14 +131,14 @@ void mailbox_test(void)
PRINT_ONE_RESULT(); PRINT_ONE_RESULT();
EmptyMsgPutTime = puttime; EmptyMsgPutTime = puttime;
for (putsize = 8; putsize <= MESSAGE_SIZE; putsize <<= 1) { for (putsize = 8; putsize <= MESSAGE_SIZE; putsize <<= 1) {
mailbox_put(putsize, putcount, &puttime); mailbox_put(putsize, putcount, &puttime);
task_fifo_get_wait(MB_COMM, &getinfo); /* waiting for ack */ task_fifo_get_wait(MB_COMM, &getinfo); /* waiting for ack */
PRINT_ONE_RESULT(); PRINT_ONE_RESULT();
} }
PRINT_STRING(dashline, output_file); PRINT_STRING(dashline, output_file);
PRINT_OVERHEAD(); PRINT_OVERHEAD();
PRINT_XFER_RATE(); PRINT_XFER_RATE();
} }
/******************************************************************************* /*******************************************************************************
@ -147,15 +147,15 @@ void mailbox_test(void)
* *
* RETURNS: N/A * RETURNS: N/A
* *
* @param size The size of the data chunk.
* @param count Number of data chunks.
* @param time The total time.
*
* \NOMANUAL * \NOMANUAL
*/ */
void mailbox_put( void mailbox_put(uint32_t size, int count, uint32_t *time)
uint32_t size, /* the size of the data chunk */ {
int count, /* number of data chunks */
uint32_t *time /* the total time */
)
{
int i; int i;
unsigned int t; unsigned int t;
@ -163,15 +163,15 @@ void mailbox_put(
Message.tx_data = data_bench; Message.tx_data = data_bench;
Message.size = size; Message.size = size;
/* first sync with the receiver */ /* first sync with the receiver */
task_sem_give(SEM0); task_sem_give(SEM0);
t = BENCH_START(); t = BENCH_START();
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
task_mbox_put_wait(MAILB1, 1, &Message); task_mbox_put_wait(MAILB1, 1, &Message);
} }
t = TIME_STAMP_DELTA_GET(t); t = TIME_STAMP_DELTA_GET(t);
*time = SYS_CLOCK_HW_CYCLES_TO_NS_AVG(t, count); *time = SYS_CLOCK_HW_CYCLES_TO_NS_AVG(t, count);
check_result(); check_result();
} }
#endif /* MAILBOX_BENCH */ #endif /* MAILBOX_BENCH */

View file

@ -56,7 +56,7 @@ int mailbox_get(kmbox_t mailbox,int size,int count,unsigned int* time);
*/ */
void mailrecvtask(void) void mailrecvtask(void)
{ {
int getsize; int getsize;
unsigned int gettime; unsigned int gettime;
int getcount; int getcount;
@ -72,13 +72,13 @@ void mailrecvtask(void)
task_fifo_put_wait(MB_COMM, &getinfo); /* acknowledge to master */ task_fifo_put_wait(MB_COMM, &getinfo); /* acknowledge to master */
for (getsize = 8; getsize <= MESSAGE_SIZE; getsize <<= 1) { for (getsize = 8; getsize <= MESSAGE_SIZE; getsize <<= 1) {
mailbox_get(MAILB1, getsize, getcount, &gettime); mailbox_get(MAILB1, getsize, getcount, &gettime);
getinfo.time = gettime; getinfo.time = gettime;
getinfo.size = getsize; getinfo.size = getsize;
getinfo.count = getcount; getinfo.count = getcount;
task_fifo_put_wait(MB_COMM, &getinfo); /* acknowledge to master */ task_fifo_put_wait(MB_COMM, &getinfo); /* acknowledge to master */
}
} }
}
/******************************************************************************* /*******************************************************************************
@ -87,16 +87,16 @@ void mailrecvtask(void)
* *
* RETURNS: 0 * RETURNS: 0
* *
* @param mailbox The mailbox to read data from.
* @param size Size of each data portion.
* @param count Number of data portions.
* @param time Resulting time.
*
* \NOMANUAL * \NOMANUAL
*/ */
int mailbox_get( int mailbox_get(kmbox_t mailbox, int size, int count, unsigned int* time)
kmbox_t mailbox, /* the mailbox to read data from */ {
int size, /* size of each data portion */
int count, /* number of data portions */
unsigned int* time /* resulting time */
)
{
int i; int i;
unsigned int t; unsigned int t;
struct k_msg Message; struct k_msg Message;
@ -105,18 +105,19 @@ int mailbox_get(
Message.rx_data = data_recv; Message.rx_data = data_recv;
Message.size = size; Message.size = size;
/* sync with the sender */ /* sync with the sender */
task_sem_take_wait(SEM0); task_sem_take_wait(SEM0);
t = BENCH_START(); t = BENCH_START();
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
task_mbox_get_wait(mailbox, &Message); task_mbox_get_wait(mailbox, &Message);
} }
t = TIME_STAMP_DELTA_GET(t); t = TIME_STAMP_DELTA_GET(t);
*time = SYS_CLOCK_HW_CYCLES_TO_NS_AVG(t, count); *time = SYS_CLOCK_HW_CYCLES_TO_NS_AVG(t, count);
if (bench_test_end() < 0) if (bench_test_end() < 0) {
PRINT_OVERFLOW_ERROR(); PRINT_OVERFLOW_ERROR();
return 0;
} }
return 0;
}
#endif /* MAILBOX_BENCH */ #endif /* MAILBOX_BENCH */

View file

@ -45,8 +45,7 @@ char Msg[MAX_MSG];
char data_bench[OCTET_TO_SIZEOFUNIT(MESSAGE_SIZE)]; char data_bench[OCTET_TO_SIZEOFUNIT(MESSAGE_SIZE)];
#ifdef PIPE_BENCH #ifdef PIPE_BENCH
kpipe_t TestPipes[] = { kpipe_t TestPipes[] = {PIPE_NOBUFF, PIPE_SMALLBUFF, PIPE_BIGBUFF};
PIPE_NOBUFF, PIPE_SMALLBUFF, PIPE_BIGBUFF};
#endif #endif
const char dashline[] = const char dashline[] =
"|--------------------------------------" "|--------------------------------------"
@ -83,22 +82,22 @@ int kbhit(void)
* *
* RETURNS: N/A * RETURNS: N/A
* *
* @param continuously Run test till the user presses the key.
* @param autorun Expect user input.
*
* \NOMANUAL * \NOMANUAL
*/ */
void init_output( void init_output(int *continuously, int *autorun)
int *continuously, /* run test till the user presses the key */ {
int *autorun /* expect user input */
)
{
ARG_UNUSED(continuously); ARG_UNUSED(continuously);
ARG_UNUSED(autorun); ARG_UNUSED(autorun);
/* /*
* send all printf and fprintf to console * send all printf and fprintf to console
*/ */
output_file = stdout; output_file = stdout;
} }
/******************************************************************************* /*******************************************************************************
* *
@ -110,8 +109,8 @@ void init_output(
*/ */
void output_close(void) void output_close(void)
{ {
} }
/* no need to wait for user key press when using console */ /* no need to wait for user key press when using console */
#define WAIT_FOR_USER() {} #define WAIT_FOR_USER() {}
@ -128,7 +127,7 @@ void output_close(void)
/* see config.h to select or to unselect*/ /* see config.h to select or to unselect*/
void BenchTask(void) void BenchTask(void)
{ {
int autorun = 0, continuously = 0; int autorun = 0, continuously = 0;
init_output(&continuously, &autorun); init_output(&continuously, &autorun);
@ -136,40 +135,40 @@ void BenchTask(void)
PRINT_STRING(newline, output_file); PRINT_STRING(newline, output_file);
do { do {
PRINT_STRING(dashline, output_file); PRINT_STRING(dashline, output_file);
PRINT_STRING("| S I M P L E S E R V I C E " PRINT_STRING("| S I M P L E S E R V I C E "
"M E A S U R E M E N T S | nsec |\n", "M E A S U R E M E N T S | nsec |\n",
output_file); output_file);
PRINT_STRING(dashline, output_file); PRINT_STRING(dashline, output_file);
task_start(RECVTASK); task_start(RECVTASK);
call_test(); call_test();
queue_test(); queue_test();
sema_test(); sema_test();
mutex_test(); mutex_test();
memorymap_test(); memorymap_test();
mempool_test(); mempool_test();
event_test(); event_test();
mailbox_test(); mailbox_test();
pipe_test(); pipe_test();
PRINT_STRING("| END OF TESTS " PRINT_STRING("| END OF TESTS "
" |\n", " |\n",
output_file); output_file);
PRINT_STRING(dashline, output_file); PRINT_STRING(dashline, output_file);
PRINT_STRING("VXMICRO PROJECT EXECUTION SUCCESSFUL\n",output_file); PRINT_STRING("VXMICRO PROJECT EXECUTION SUCCESSFUL\n",output_file);
} } while (continuously && !kbhit());
while (continuously && !kbhit());
WAIT_FOR_USER(); WAIT_FOR_USER();
/* /*
* Make a 2 second delay. sys_clock_ticks_per_sec in this context is * Make a 2 second delay. sys_clock_ticks_per_sec in this context is
* a number of system times ticks in a second. * a number of system times ticks in a second.
*/ */
if (autorun) if (autorun) {
task_sleep(2 * sys_clock_ticks_per_sec); task_sleep(2 * sys_clock_ticks_per_sec);
}
output_close(); output_close();
} }
/******************************************************************************* /*******************************************************************************
@ -182,6 +181,6 @@ void BenchTask(void)
*/ */
void dummy_test(void) void dummy_test(void)
{ {
return; return;
} }

View file

@ -148,33 +148,31 @@ extern void event_test(void);
* is defined in the main file * is defined in the main file
*/ */
#define PRINT_F(stream, fmt, ...) \ #define PRINT_F(stream, fmt, ...) \
{ \ { \
snprintf(sline, SLINE_LEN, fmt, ##__VA_ARGS__); \ snprintf(sline, SLINE_LEN, fmt, ##__VA_ARGS__); \
PRINT_STRING(sline, stream); \ PRINT_STRING(sline, stream); \
} }
#define PRINT_OVERFLOW_ERROR() \ #define PRINT_OVERFLOW_ERROR() \
PRINT_F(output_file, \ PRINT_F(output_file, __FILE__":%d Error: tick occured\n", __LINE__)
__FILE__":%d Error: tick occured\n", __LINE__)
static inline uint32_t BENCH_START(void) static inline uint32_t BENCH_START(void)
{ {
uint32_t et; uint32_t et;
bench_test_start(); bench_test_start();
et = TIME_STAMP_DELTA_GET(0); et = TIME_STAMP_DELTA_GET(0);
return et; return et;
} }
#define check_result() \ #define check_result() \
{ \ { \
if (bench_test_end() < 0) \ if (bench_test_end() < 0) { \
{ \ PRINT_OVERFLOW_ERROR(); \
PRINT_OVERFLOW_ERROR(); \ return; /* error */ \
return; /* error */ \ } \
} \ }
}
#endif /* _MASTER_H */ #endif /* _MASTER_H */

View file

@ -46,7 +46,7 @@
*/ */
void memorymap_test(void) void memorymap_test(void)
{ {
uint32_t et; /* elapsed time */ uint32_t et; /* elapsed time */
int i; int i;
void* p; void* p;
@ -54,14 +54,14 @@ void memorymap_test(void)
PRINT_STRING(dashline, output_file); PRINT_STRING(dashline, output_file);
et = BENCH_START(); et = BENCH_START();
for (i = 0; i < NR_OF_MAP_RUNS; i++) { for (i = 0; i < NR_OF_MAP_RUNS; i++) {
task_mem_map_alloc_wait(MAP1, &p); task_mem_map_alloc_wait(MAP1, &p);
task_mem_map_free(MAP1, &p); task_mem_map_free(MAP1, &p);
} }
et = TIME_STAMP_DELTA_GET(et); et = TIME_STAMP_DELTA_GET(et);
check_result(); check_result();
PRINT_F(output_file, FORMAT, "average alloc and dealloc memory page", PRINT_F(output_file, FORMAT, "average alloc and dealloc memory page",
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, (2 * NR_OF_MAP_RUNS))); SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, (2 * NR_OF_MAP_RUNS)));
} }
#endif /* MEMMAP_BENCH */ #endif /* MEMMAP_BENCH */

View file

@ -44,7 +44,7 @@
*/ */
void mempool_test(void) void mempool_test(void)
{ {
uint32_t et; /* elapsed time */ uint32_t et; /* elapsed time */
int i; int i;
struct k_block block; struct k_block block;
@ -52,15 +52,15 @@ void mempool_test(void)
PRINT_STRING(dashline, output_file); PRINT_STRING(dashline, output_file);
et = BENCH_START(); et = BENCH_START();
for (i = 0; i < NR_OF_POOL_RUNS; i++) { for (i = 0; i < NR_OF_POOL_RUNS; i++) {
task_mem_pool_alloc_wait(&block, DEMOPOOL, 16); task_mem_pool_alloc_wait(&block, DEMOPOOL, 16);
task_mem_pool_free(&block); task_mem_pool_free(&block);
} }
et = TIME_STAMP_DELTA_GET(et); et = TIME_STAMP_DELTA_GET(et);
check_result(); check_result();
PRINT_F(output_file, FORMAT, PRINT_F(output_file, FORMAT,
"average alloc and dealloc memory pool block", "average alloc and dealloc memory pool block",
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, (2 * NR_OF_POOL_RUNS))); SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, (2 * NR_OF_POOL_RUNS)));
} }
#endif /* MEMPOOL_BENCH */ #endif /* MEMPOOL_BENCH */

View file

@ -44,21 +44,21 @@
*/ */
void mutex_test(void) void mutex_test(void)
{ {
uint32_t et; /* elapsed time */ uint32_t et; /* elapsed time */
int i; int i;
PRINT_STRING(dashline, output_file); PRINT_STRING(dashline, output_file);
et = BENCH_START(); et = BENCH_START();
for (i = 0; i < NR_OF_MUTEX_RUNS; i++) { for (i = 0; i < NR_OF_MUTEX_RUNS; i++) {
task_mutex_lock_wait(DEMO_MUTEX); task_mutex_lock_wait(DEMO_MUTEX);
task_mutex_unlock(DEMO_MUTEX); task_mutex_unlock(DEMO_MUTEX);
} }
et = TIME_STAMP_DELTA_GET(et); et = TIME_STAMP_DELTA_GET(et);
check_result(); check_result();
PRINT_F(output_file, FORMAT, "average lock and unlock mutex", PRINT_F(output_file, FORMAT, "average lock and unlock mutex",
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, (2 * NR_OF_MUTEX_RUNS))); SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, (2 * NR_OF_MUTEX_RUNS)));
} }
#endif /* MUTEX_BENCH */ #endif /* MUTEX_BENCH */

View file

@ -48,19 +48,19 @@ extern void _task_nop(void);
*/ */
void call_test(void) void call_test(void)
{ {
uint32_t et; /* Elapsed Time */ uint32_t et; /* Elapsed Time */
int i; int i;
et = BENCH_START(); et = BENCH_START();
for (i = 0; i < NR_OF_NOP_RUNS; i++) { for (i = 0; i < NR_OF_NOP_RUNS; i++) {
_task_nop(); _task_nop();
} }
et = TIME_STAMP_DELTA_GET(et); et = TIME_STAMP_DELTA_GET(et);
check_result(); check_result();
PRINT_F(output_file, FORMAT, "minimum VxMicro call time", PRINT_F(output_file, FORMAT, "minimum VxMicro call time",
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_NOP_RUNS)); SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_NOP_RUNS));
} }
#endif /* MICROKERNEL_CALL_BENCH */ #endif /* MICROKERNEL_CALL_BENCH */

View file

@ -117,7 +117,7 @@ int pipeput(kpipe_t pipe, K_PIPE_OPTION
*/ */
void pipe_test(void) void pipe_test(void)
{ {
uint32_t putsize; uint32_t putsize;
int getsize; int getsize;
uint32_t puttime[3]; uint32_t puttime[3];
@ -130,76 +130,76 @@ void pipe_test(void)
task_sem_reset(SEM0); task_sem_reset(SEM0);
task_sem_give(STARTRCV); task_sem_give(STARTRCV);
/* action: */ /* action: */
/* non-buffered operation, matching (ALL_N) */ /* non-buffered operation, matching (ALL_N) */
PRINT_STRING(dashline, output_file); PRINT_STRING(dashline, output_file);
PRINT_STRING("| " PRINT_STRING("| "
"C H A N N E L M E A S U R E M E N T S" "C H A N N E L M E A S U R E M E N T S"
" |\n", output_file); " |\n", output_file);
PRINT_STRING(dashline, output_file); PRINT_STRING(dashline, output_file);
PRINT_STRING("| Send data into a pipe towards a " PRINT_STRING("| Send data into a pipe towards a "
"receiving high priority task and wait |\n", "receiving high priority task and wait |\n",
output_file); output_file);
PRINT_STRING(dashline, output_file); PRINT_STRING(dashline, output_file);
PRINT_STRING("| " PRINT_STRING("| "
"matching sizes (_ALL_N)" "matching sizes (_ALL_N)"
" |\n", output_file); " |\n", output_file);
PRINT_STRING(dashline, output_file); PRINT_STRING(dashline, output_file);
PRINT_ALL_TO_N_HEADER_UNIT(); PRINT_ALL_TO_N_HEADER_UNIT();
PRINT_STRING(dashline, output_file); PRINT_STRING(dashline, output_file);
PRINT_STRING("| put | get | no buf | small buf| big buf |" PRINT_STRING("| put | get | no buf | small buf| big buf |"
" no buf | small buf| big buf |\n", output_file); " no buf | small buf| big buf |\n", output_file);
PRINT_STRING(dashline, output_file); PRINT_STRING(dashline, output_file);
for (putsize = 8; putsize <= MESSAGE_SIZE_PIPE; putsize <<= 1) { for (putsize = 8; putsize <= MESSAGE_SIZE_PIPE; putsize <<= 1) {
for (pipe = 0; pipe < 3; pipe++) { for (pipe = 0; pipe < 3; pipe++) {
putcount = NR_OF_PIPE_RUNS; putcount = NR_OF_PIPE_RUNS;
pipeput(TestPipes[pipe], _ALL_N, putsize, putcount, pipeput(TestPipes[pipe], _ALL_N, putsize, putcount,
&puttime[pipe]); &puttime[pipe]);
task_fifo_get_wait(CH_COMM, &getinfo); /* waiting for ack */ task_fifo_get_wait(CH_COMM, &getinfo); /* waiting for ack */
}
PRINT_ALL_TO_N();
}
PRINT_STRING(dashline, output_file);
/* Test with two different sender priorities */
for (prio = 0; prio < 2; prio++) {
/* non-buffered operation, non-matching (1_TO_N) */
if (prio == 0) {
PRINT_STRING("| "
"non-matching sizes (1_TO_N) to higher priority"
" |\n", output_file);
TaskPrio = task_priority_get();
}
if (prio == 1) {
PRINT_STRING("| "
"non-matching sizes (1_TO_N) to lower priority"
" |\n", output_file);
task_priority_set(task_id_get(), TaskPrio - 2);
}
PRINT_STRING(dashline, output_file);
PRINT_1_TO_N_HEADER();
PRINT_STRING("| put | get | no buf | small buf| big buf | "
"no buf | small buf| big buf |\n", output_file);
PRINT_STRING(dashline, output_file);
for (putsize = 8; putsize <= (MESSAGE_SIZE_PIPE); putsize <<= 1) {
putcount = MESSAGE_SIZE_PIPE / putsize;
for (pipe = 0; pipe < 3; pipe++) {
pipeput(TestPipes[pipe], _1_TO_N, putsize,
putcount, &puttime[pipe]);
/* size*count == MESSAGE_SIZE_PIPE */
task_fifo_get_wait(CH_COMM, &getinfo); /* waiting for ack */
getsize = getinfo.size;
} }
PRINT_1_TO_N(); PRINT_ALL_TO_N();
} }
PRINT_STRING(dashline, output_file); PRINT_STRING(dashline, output_file);
task_priority_set(task_id_get(), TaskPrio);
} /* Test with two different sender priorities */
for (prio = 0; prio < 2; prio++) {
/* non-buffered operation, non-matching (1_TO_N) */
if (prio == 0) {
PRINT_STRING("| "
"non-matching sizes (1_TO_N) to higher priority"
" |\n", output_file);
TaskPrio = task_priority_get();
}
if (prio == 1) {
PRINT_STRING("| "
"non-matching sizes (1_TO_N) to lower priority"
" |\n", output_file);
task_priority_set(task_id_get(), TaskPrio - 2);
}
PRINT_STRING(dashline, output_file);
PRINT_1_TO_N_HEADER();
PRINT_STRING("| put | get | no buf | small buf| big buf | "
"no buf | small buf| big buf |\n", output_file);
PRINT_STRING(dashline, output_file);
for (putsize = 8; putsize <= (MESSAGE_SIZE_PIPE); putsize <<= 1) {
putcount = MESSAGE_SIZE_PIPE / putsize;
for (pipe = 0; pipe < 3; pipe++) {
pipeput(TestPipes[pipe], _1_TO_N, putsize,
putcount, &puttime[pipe]);
/* size*count == MESSAGE_SIZE_PIPE */
task_fifo_get_wait(CH_COMM, &getinfo); /* waiting for ack */
getsize = getinfo.size;
}
PRINT_1_TO_N();
}
PRINT_STRING(dashline, output_file);
task_priority_set(task_id_get(), TaskPrio);
} }
}
/******************************************************************************* /*******************************************************************************
@ -208,60 +208,63 @@ void pipe_test(void)
* *
* RETURNS: 0 on success, 1 on error * RETURNS: 0 on success, 1 on error
* *
* @param pipe The pipe to be tested.
* @param option _ALL_TO_N or _1_TO_N.
* @param size Data chunk size.
* @param count Number of data chunks.
* @param time Total write time.
*
* \NOMANUAL * \NOMANUAL
*/ */
int pipeput( int pipeput(kpipe_t pipe, K_PIPE_OPTION option, int size, int count, uint32_t *time)
kpipe_t pipe, /* The pipe to be tested */ {
K_PIPE_OPTION option, /* _ALL_TO_N or _1_TO_N */
int size, /* data chunk size */
int count, /* number of data chunks */
uint32_t *time /* total write time */
)
{
int i; int i;
unsigned int t; unsigned int t;
int sizexferd_total = 0; int sizexferd_total = 0;
int size2xfer_total = size * count; int size2xfer_total = size * count;
/* first sync with the receiver */ /* first sync with the receiver */
task_sem_give(SEM0); task_sem_give(SEM0);
t = BENCH_START(); t = BENCH_START();
for (i = 0; _1_TO_N == option || (i < count); i++) { for (i = 0; _1_TO_N == option || (i < count); i++) {
int sizexferd = 0; int sizexferd = 0;
int size2xfer = min(size, size2xfer_total - sizexferd_total); int size2xfer = min(size, size2xfer_total - sizexferd_total);
int ret; int ret;
ret = task_pipe_put_wait(pipe, data_bench, size2xfer, ret = task_pipe_put_wait(pipe, data_bench, size2xfer,
&sizexferd, option); &sizexferd, option);
if (RC_OK != ret) if (RC_OK != ret) {
return 1; return 1;
if (_ALL_N == option && sizexferd != size2xfer) }
return 1; if (_ALL_N == option && sizexferd != size2xfer) {
return 1;
}
sizexferd_total += sizexferd; sizexferd_total += sizexferd;
if (size2xfer_total == sizexferd_total) if (size2xfer_total == sizexferd_total) {
break; break;
}
if (size2xfer_total < sizexferd_total) if (size2xfer_total < sizexferd_total) {
return 1; return 1;
}
} }
t = TIME_STAMP_DELTA_GET(t); t = TIME_STAMP_DELTA_GET(t);
*time = SYS_CLOCK_HW_CYCLES_TO_NS_AVG(t, count); *time = SYS_CLOCK_HW_CYCLES_TO_NS_AVG(t, count);
if (bench_test_end() < 0) { if (bench_test_end() < 0) {
if (high_timer_overflow()) { if (high_timer_overflow()) {
PRINT_STRING("| Timer overflow. Results are invalid ", PRINT_STRING("| Timer overflow. Results are invalid ",
output_file); output_file);
} }
else { else {
PRINT_STRING("| Tick occured. Results may be inaccurate ", PRINT_STRING("| Tick occured. Results may be inaccurate ",
output_file); output_file);
} }
PRINT_STRING(" |\n", PRINT_STRING(" |\n", output_file);
output_file);
} }
return 0; return 0;
} }
#endif /* PIPE_BENCH */ #endif /* PIPE_BENCH */

View file

@ -39,7 +39,7 @@
* Function prototypes. * Function prototypes.
*/ */
int pipeget(kpipe_t pipe, K_PIPE_OPTION option, int pipeget(kpipe_t pipe, K_PIPE_OPTION option,
int size, int count, unsigned int* time); int size, int count, unsigned int* time);
/* /*
* Function declarations. * Function declarations.
@ -57,7 +57,7 @@ int pipeget(kpipe_t pipe, K_PIPE_OPTION option,
*/ */
void piperecvtask(void) void piperecvtask(void)
{ {
int getsize; int getsize;
unsigned int gettime; unsigned int gettime;
int getcount; int getcount;
@ -65,37 +65,37 @@ void piperecvtask(void)
int prio; int prio;
GetInfo getinfo; GetInfo getinfo;
/* matching (ALL_N) */ /* matching (ALL_N) */
for (getsize = 8; getsize <= MESSAGE_SIZE_PIPE; getsize <<= 1) { for (getsize = 8; getsize <= MESSAGE_SIZE_PIPE; getsize <<= 1) {
for (pipe = 0; pipe < 3; pipe++) { for (pipe = 0; pipe < 3; pipe++) {
getcount = NR_OF_PIPE_RUNS; getcount = NR_OF_PIPE_RUNS;
pipeget(TestPipes[pipe], _ALL_N, getsize, pipeget(TestPipes[pipe], _ALL_N, getsize,
getcount, &gettime); getcount, &gettime);
getinfo.time = gettime; getinfo.time = gettime;
getinfo.size = getsize; getinfo.size = getsize;
getinfo.count = getcount; getinfo.count = getcount;
task_fifo_put_wait(CH_COMM, &getinfo); /* acknowledge to master */ task_fifo_put_wait(CH_COMM, &getinfo); /* acknowledge to master */
} }
} }
for (prio = 0; prio < 2; prio++) { for (prio = 0; prio < 2; prio++) {
/* non-matching (1_TO_N) */ /* non-matching (1_TO_N) */
for (getsize = (MESSAGE_SIZE_PIPE); getsize >= 8; getsize >>= 1) { for (getsize = (MESSAGE_SIZE_PIPE); getsize >= 8; getsize >>= 1) {
getcount = MESSAGE_SIZE_PIPE / getsize; getcount = MESSAGE_SIZE_PIPE / getsize;
for (pipe = 0; pipe < 3; pipe++) { for (pipe = 0; pipe < 3; pipe++) {
/* size*count == MESSAGE_SIZE_PIPE */ /* size*count == MESSAGE_SIZE_PIPE */
pipeget(TestPipes[pipe], _1_TO_N, pipeget(TestPipes[pipe], _1_TO_N,
getsize, getcount, &gettime); getsize, getcount, &gettime);
getinfo.time = gettime; getinfo.time = gettime;
getinfo.size = getsize; getinfo.size = getsize;
getinfo.count = getcount; getinfo.count = getcount;
task_fifo_put_wait(CH_COMM, &getinfo); /* acknowledge to master */ task_fifo_put_wait(CH_COMM, &getinfo); /* acknowledge to master */
}
} }
}
} }
} }
/******************************************************************************* /*******************************************************************************
@ -104,61 +104,66 @@ void piperecvtask(void)
* *
* RETURNS: 0 on success, 1 on error * RETURNS: 0 on success, 1 on error
* *
* @param pipe Pipe to read data from.
* @param option _ALL_TO_N or _1_TO_N.
* @param size Data chunk size.
* @param count Number of data chunks.
* @param time Total write time.
*
* \NOMANUAL * \NOMANUAL
*/ */
int pipeget( int pipeget(kpipe_t pipe, K_PIPE_OPTION option, int size, int count,
kpipe_t pipe, /* pipe to read data from */ unsigned int* time)
K_PIPE_OPTION option, /* _ALL_TO_N or _1_TO_N */ {
int size, /* data chunk size */
int count, /* number of data chunks */
unsigned int* time /* total write time */
)
{
int i; int i;
unsigned int t; unsigned int t;
int sizexferd_total = 0; int sizexferd_total = 0;
int size2xfer_total = size * count; int size2xfer_total = size * count;
/* sync with the sender */ /* sync with the sender */
task_sem_take_wait(SEM0); task_sem_take_wait(SEM0);
t = BENCH_START(); t = BENCH_START();
for (i = 0; _1_TO_N == option || (i < count); i++) { for (i = 0; _1_TO_N == option || (i < count); i++) {
int sizexferd = 0; int sizexferd = 0;
int size2xfer = min(size, size2xfer_total - sizexferd_total); int size2xfer = min(size, size2xfer_total - sizexferd_total);
int ret; int ret;
ret = task_pipe_get_wait(pipe, data_recv, size2xfer, ret = task_pipe_get_wait(pipe, data_recv, size2xfer,
&sizexferd, option); &sizexferd, option);
if (RC_OK != ret) if (RC_OK != ret) {
return 1; return 1;
}
if (_ALL_N == option && sizexferd != size2xfer) if (_ALL_N == option && sizexferd != size2xfer) {
return 1; return 1;
}
sizexferd_total += sizexferd; sizexferd_total += sizexferd;
if (size2xfer_total == sizexferd_total) if (size2xfer_total == sizexferd_total) {
break; break;
}
if (size2xfer_total < sizexferd_total) if (size2xfer_total < sizexferd_total) {
return 1; return 1;
}
} }
t = TIME_STAMP_DELTA_GET(t); t = TIME_STAMP_DELTA_GET(t);
*time = SYS_CLOCK_HW_CYCLES_TO_NS_AVG(t, count); *time = SYS_CLOCK_HW_CYCLES_TO_NS_AVG(t, count);
if (bench_test_end() < 0) { if (bench_test_end() < 0) {
if (high_timer_overflow()) { if (high_timer_overflow()) {
PRINT_STRING("| Timer overflow. Results are invalid ", PRINT_STRING("| Timer overflow. Results are invalid ",
output_file); output_file);
} }
else { else {
PRINT_STRING("| Tick occured. Results may be inaccurate ", PRINT_STRING("| Tick occured. Results may be inaccurate ",
output_file); output_file);
} }
PRINT_STRING(" |\n", PRINT_STRING(" |\n",
output_file); output_file);
} }
return 0; return 0;
} }
#endif /* PIPE_BENCH */ #endif /* PIPE_BENCH */

View file

@ -41,9 +41,7 @@
#include "receiver.h" #include "receiver.h"
char data_recv[OCTET_TO_SIZEOFUNIT(MESSAGE_SIZE)] = { char data_recv[OCTET_TO_SIZEOFUNIT(MESSAGE_SIZE)] = { 0 };
0
};
void dequtask(void); void dequtask(void);
void waittask(void); void waittask(void);
@ -60,8 +58,8 @@ void piperecvtask(void);
*/ */
void recvtask(void) void recvtask(void)
{ {
/* order must be compatible with master.c ! */ /* order must be compatible with master.c ! */
#ifdef FIFO_BENCH #ifdef FIFO_BENCH
task_sem_take_wait(STARTRCV); task_sem_take_wait(STARTRCV);
dequtask(); dequtask();
@ -78,4 +76,4 @@ void recvtask(void)
task_sem_take_wait(STARTRCV); task_sem_take_wait(STARTRCV);
piperecvtask(); piperecvtask();
#endif #endif
} }

View file

@ -42,7 +42,7 @@ typedef struct {
int count; int count;
unsigned int time; unsigned int time;
int size; int size;
} GetInfo; } GetInfo;
/* global data */ /* global data */
extern char data_recv[OCTET_TO_SIZEOFUNIT(MESSAGE_SIZE)]; extern char data_recv[OCTET_TO_SIZEOFUNIT(MESSAGE_SIZE)];

View file

@ -45,104 +45,104 @@
*/ */
void sema_test(void) void sema_test(void)
{ {
uint32_t et; /* elapsed Time */ uint32_t et; /* elapsed Time */
int i; int i;
PRINT_STRING(dashline, output_file); PRINT_STRING(dashline, output_file);
et = BENCH_START(); et = BENCH_START();
for (i = 0; i < NR_OF_SEMA_RUNS; i++) { for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
task_sem_give(SEM0); task_sem_give(SEM0);
} }
et = TIME_STAMP_DELTA_GET(et); et = TIME_STAMP_DELTA_GET(et);
check_result(); check_result();
PRINT_F(output_file, FORMAT, "signal semaphore", PRINT_F(output_file, FORMAT, "signal semaphore",
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS)); SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS));
task_sem_reset(SEM1); task_sem_reset(SEM1);
task_sem_give(STARTRCV); task_sem_give(STARTRCV);
et = BENCH_START(); et = BENCH_START();
for (i = 0; i < NR_OF_SEMA_RUNS; i++) { for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
task_sem_give(SEM1); task_sem_give(SEM1);
} }
et = TIME_STAMP_DELTA_GET(et); et = TIME_STAMP_DELTA_GET(et);
check_result(); check_result();
PRINT_F(output_file, FORMAT, "signal to waiting high pri task", PRINT_F(output_file, FORMAT, "signal to waiting high pri task",
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS)); SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS));
et = BENCH_START(); et = BENCH_START();
for (i = 0; i < NR_OF_SEMA_RUNS; i++) { for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
task_sem_give(SEM1); task_sem_give(SEM1);
} }
et = TIME_STAMP_DELTA_GET(et); et = TIME_STAMP_DELTA_GET(et);
check_result(); check_result();
PRINT_F(output_file, FORMAT, PRINT_F(output_file, FORMAT,
"signal to waiting high pri task, with timeout", "signal to waiting high pri task, with timeout",
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS)); SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS));
et = BENCH_START(); et = BENCH_START();
for (i = 0; i < NR_OF_SEMA_RUNS; i++) { for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
task_sem_give(SEM2); task_sem_give(SEM2);
} }
et = TIME_STAMP_DELTA_GET(et); et = TIME_STAMP_DELTA_GET(et);
check_result(); check_result();
PRINT_F(output_file, FORMAT, "signal to waitm (2)", PRINT_F(output_file, FORMAT, "signal to waitm (2)",
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS)); SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS));
et = BENCH_START(); et = BENCH_START();
for (i = 0; i < NR_OF_SEMA_RUNS; i++) { for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
task_sem_give(SEM2); task_sem_give(SEM2);
} }
et = TIME_STAMP_DELTA_GET(et); et = TIME_STAMP_DELTA_GET(et);
check_result(); check_result();
PRINT_F(output_file, FORMAT, "signal to waitm (2), with timeout", PRINT_F(output_file, FORMAT, "signal to waitm (2), with timeout",
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS)); SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS));
et = BENCH_START(); et = BENCH_START();
for (i = 0; i < NR_OF_SEMA_RUNS; i++) { for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
task_sem_give(SEM3); task_sem_give(SEM3);
} }
et = TIME_STAMP_DELTA_GET(et); et = TIME_STAMP_DELTA_GET(et);
check_result(); check_result();
PRINT_F(output_file, FORMAT, "signal to waitm (3)", PRINT_F(output_file, FORMAT, "signal to waitm (3)",
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS)); SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS));
et = BENCH_START(); et = BENCH_START();
for (i = 0; i < NR_OF_SEMA_RUNS; i++) { for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
task_sem_give(SEM3); task_sem_give(SEM3);
} }
et = TIME_STAMP_DELTA_GET(et); et = TIME_STAMP_DELTA_GET(et);
check_result(); check_result();
PRINT_F(output_file, FORMAT, "signal to waitm (3), with timeout", PRINT_F(output_file, FORMAT, "signal to waitm (3), with timeout",
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS)); SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS));
et = BENCH_START(); et = BENCH_START();
for (i = 0; i < NR_OF_SEMA_RUNS; i++) { for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
task_sem_give(SEM4); task_sem_give(SEM4);
} }
et = TIME_STAMP_DELTA_GET(et); et = TIME_STAMP_DELTA_GET(et);
check_result(); check_result();
PRINT_F(output_file, FORMAT, "signal to waitm (4)", PRINT_F(output_file, FORMAT, "signal to waitm (4)",
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS)); SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS));
et = BENCH_START(); et = BENCH_START();
for (i = 0; i < NR_OF_SEMA_RUNS; i++) { for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
task_sem_give(SEM4); task_sem_give(SEM4);
} }
et = TIME_STAMP_DELTA_GET(et); et = TIME_STAMP_DELTA_GET(et);
check_result(); check_result();
PRINT_F(output_file, FORMAT, "signal to waitm (4), with timeout", PRINT_F(output_file, FORMAT, "signal to waitm (4), with timeout",
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS)); SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS));
} }
#endif /* SEMA_BENCH */ #endif /* SEMA_BENCH */

View file

@ -47,7 +47,7 @@
*/ */
void waittask(void) void waittask(void)
{ {
int i; int i;
ksem_t slist[5]; ksem_t slist[5];
@ -58,27 +58,35 @@ void waittask(void)
slist[3] = ENDLIST; slist[3] = ENDLIST;
slist[4] = ENDLIST; slist[4] = ENDLIST;
for (i = 0; i < NR_OF_SEMA_RUNS; i++) for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
task_sem_take_wait(SEM1); task_sem_take_wait(SEM1);
for (i = 0; i < NR_OF_SEMA_RUNS; i++) }
task_sem_take_wait_timeout(SEM1, SEMA_WAIT_TIME); for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
task_sem_take_wait_timeout(SEM1, SEMA_WAIT_TIME);
for (i = 0; i < NR_OF_SEMA_RUNS; i++)
task_sem_group_take_wait(slist);
for (i = 0; i < NR_OF_SEMA_RUNS; i++)
task_sem_group_take_wait_timeout(slist, SEMA_WAIT_TIME);
slist[2] = SEM3;
for (i = 0; i < NR_OF_SEMA_RUNS; i++)
task_sem_group_take_wait(slist);
for (i = 0; i < NR_OF_SEMA_RUNS; i++)
task_sem_group_take_wait_timeout(slist, SEMA_WAIT_TIME);
slist[3] = SEM4;
for (i = 0; i < NR_OF_SEMA_RUNS; i++)
task_sem_group_take_wait(slist);
for (i = 0; i < NR_OF_SEMA_RUNS; i++)
task_sem_group_take_wait_timeout(slist, SEMA_WAIT_TIME);
} }
for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
task_sem_group_take_wait(slist);
}
for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
task_sem_group_take_wait_timeout(slist, SEMA_WAIT_TIME);
}
slist[2] = SEM3;
for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
task_sem_group_take_wait(slist);
}
for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
task_sem_group_take_wait_timeout(slist, SEMA_WAIT_TIME);
}
slist[3] = SEM4;
for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
task_sem_group_take_wait(slist);
}
for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
task_sem_group_take_wait_timeout(slist, SEMA_WAIT_TIME);
}
}
#endif /* SEMA_BENCH */ #endif /* SEMA_BENCH */

View file

@ -56,7 +56,7 @@ extern uint64_t __main_tsc; /* timestamp when main() begins executing */
extern uint64_t __idle_tsc; /* timestamp when CPU went idle */ extern uint64_t __idle_tsc; /* timestamp when CPU went idle */
void bootTimeTask(void) void bootTimeTask(void)
{ {
uint64_t task_tsc; /* timestamp at beginning of first task */ uint64_t task_tsc; /* timestamp at beginning of first task */
uint64_t _start_us; /* being of __start timestamp in us */ uint64_t _start_us; /* being of __start timestamp in us */
uint64_t main_us; /* begin of main timestamp in us */ uint64_t main_us; /* begin of main timestamp in us */
@ -70,7 +70,7 @@ void bootTimeTask(void)
task_tsc = _NanoTscRead(); task_tsc = _NanoTscRead();
#ifndef CONFIG_NANOKERNEL #ifndef CONFIG_NANOKERNEL
/* Go to sleep for 1 tick in order to timestamp when IdleTask halts. */ /* Go to sleep for 1 tick in order to timestamp when IdleTask halts. */
task_sleep(1); task_sleep(1);
#endif /* ! CONFIG_NANOKERNEL */ #endif /* ! CONFIG_NANOKERNEL */
@ -84,30 +84,30 @@ void bootTimeTask(void)
idle_us = s_idle_tsc / CONFIG_CPU_CLOCK_FREQ_MHZ; idle_us = s_idle_tsc / CONFIG_CPU_CLOCK_FREQ_MHZ;
#endif #endif
/* Indicate start for sanity test suite */ /* Indicate start for sanity test suite */
TC_START("Boot Time Measurement"); TC_START("Boot Time Measurement");
/* Only print lower 32bit of time result */ /* Only print lower 32bit of time result */
#ifdef CONFIG_NANOKERNEL #ifdef CONFIG_NANOKERNEL
TC_PRINT("NanoKernel Boot Result: Clock Frequency: %d MHz\n", TC_PRINT("NanoKernel Boot Result: Clock Frequency: %d MHz\n",
CONFIG_CPU_CLOCK_FREQ_MHZ); CONFIG_CPU_CLOCK_FREQ_MHZ);
#else /* CONFIG_MICROKERNEL */ #else /* CONFIG_MICROKERNEL */
TC_PRINT("MicroKernel Boot Result: Clock Frequency: %d MHz\n", TC_PRINT("MicroKernel Boot Result: Clock Frequency: %d MHz\n",
CONFIG_CPU_CLOCK_FREQ_MHZ); CONFIG_CPU_CLOCK_FREQ_MHZ);
#endif #endif
TC_PRINT("__start : %d cycles, %d us\n", TC_PRINT("__start : %d cycles, %d us\n",
(uint32_t)(__start_tsc & 0xFFFFFFFFULL), (uint32_t)(__start_tsc & 0xFFFFFFFFULL),
(uint32_t) (_start_us & 0xFFFFFFFFULL)); (uint32_t) (_start_us & 0xFFFFFFFFULL));
TC_PRINT("_start->main(): %d cycles, %d us\n", TC_PRINT("_start->main(): %d cycles, %d us\n",
(uint32_t)(s_main_tsc & 0xFFFFFFFFULL), (uint32_t)(s_main_tsc & 0xFFFFFFFFULL),
(uint32_t) (main_us & 0xFFFFFFFFULL)); (uint32_t) (main_us & 0xFFFFFFFFULL));
TC_PRINT("_start->task : %d cycles, %d us\n", TC_PRINT("_start->task : %d cycles, %d us\n",
(uint32_t)(s_task_tsc & 0xFFFFFFFFULL), (uint32_t)(s_task_tsc & 0xFFFFFFFFULL),
(uint32_t) (task_us & 0xFFFFFFFFULL)); (uint32_t) (task_us & 0xFFFFFFFFULL));
#ifndef CONFIG_NANOKERNEL /* CONFIG_MICROKERNEL */ #ifndef CONFIG_NANOKERNEL /* CONFIG_MICROKERNEL */
TC_PRINT("_start->idle : %d cycles, %d us\n", TC_PRINT("_start->idle : %d cycles, %d us\n",
(uint32_t)(s_idle_tsc & 0xFFFFFFFFULL), (uint32_t)(s_idle_tsc & 0xFFFFFFFFULL),
(uint32_t) (idle_us & 0xFFFFFFFFULL)); (uint32_t) (idle_us & 0xFFFFFFFFULL));
#endif #endif
@ -117,7 +117,7 @@ void bootTimeTask(void)
TC_END_RESULT(TC_PASS); TC_END_RESULT(TC_PASS);
TC_END_REPORT(TC_PASS); TC_END_REPORT(TC_PASS);
} }
#ifdef CONFIG_NANOKERNEL #ifdef CONFIG_NANOKERNEL
@ -131,13 +131,13 @@ char fiberStack[512];
*/ */
void main(void) void main(void)
{ {
/* record timestamp for nanokernel's main() function */ /* record timestamp for nanokernel's main() function */
__main_tsc = _NanoTscRead(); __main_tsc = _NanoTscRead();
/* create bootTime fibers */ /* create bootTime fibers */
task_fiber_start(fiberStack, 512, task_fiber_start(fiberStack, 512,
(nano_fiber_entry_t) bootTimeTask, 0, 0, 6, 0); (nano_fiber_entry_t) bootTimeTask, 0, 0, 6, 0);
} }
#endif /* CONFIG_NANOKERNEL */ #endif /* CONFIG_NANOKERNEL */

View file

@ -84,27 +84,27 @@ NANO_CPU_INT_REGISTER(isrDummyIntStub, TEST_SOFT_INT, 0);
/* pointer array ensures specified functions are linked into the image */ /* pointer array ensures specified functions are linked into the image */
static pfunc func_array[] = { static pfunc func_array[] = {
/* event functions */ /* event functions */
(pfunc)task_event_send, (pfunc)task_event_send,
(pfunc)_task_event_recv, (pfunc)_task_event_recv,
/* mutex functions */ /* mutex functions */
(pfunc)_task_mutex_lock, (pfunc)_task_mutex_lock,
(pfunc)_task_mutex_unlock, (pfunc)_task_mutex_unlock,
/* FIFO functions */ /* FIFO functions */
(pfunc)_task_fifo_put, (pfunc)_task_fifo_put,
(pfunc)_task_fifo_get, (pfunc)_task_fifo_get,
(pfunc)_task_fifo_ioctl, (pfunc)_task_fifo_ioctl,
/* memory map functions */ /* memory map functions */
(pfunc)task_mem_map_used_get, (pfunc)task_mem_map_used_get,
(pfunc)_task_mem_map_alloc, (pfunc)_task_mem_map_alloc,
(pfunc)_task_mem_map_free, (pfunc)_task_mem_map_free,
#ifdef TEST_max #ifdef TEST_max
/* task device interrupt functions */ /* task device interrupt functions */
(pfunc)task_irq_alloc, (pfunc)task_irq_alloc,
(pfunc)_task_irq_test, (pfunc)_task_irq_test,
(pfunc)task_irq_ack, (pfunc)task_irq_ack,
(pfunc)task_irq_free, (pfunc)task_irq_free,
/* semaphore functions */ /* semaphore functions */
(pfunc)isr_sem_give, (pfunc)isr_sem_give,
(pfunc)task_sem_give, (pfunc)task_sem_give,
(pfunc)task_sem_group_give, (pfunc)task_sem_group_give,
@ -113,7 +113,7 @@ static pfunc func_array[] = {
(pfunc)task_sem_group_reset, (pfunc)task_sem_group_reset,
(pfunc)_task_sem_take, (pfunc)_task_sem_take,
(pfunc)_task_sem_group_take, (pfunc)_task_sem_group_take,
/* pipe functions */ /* pipe functions */
(pfunc)task_pipe_put, (pfunc)task_pipe_put,
(pfunc)task_pipe_put_wait, (pfunc)task_pipe_put_wait,
(pfunc)task_pipe_put_wait_timeout, (pfunc)task_pipe_put_wait_timeout,
@ -123,17 +123,17 @@ static pfunc func_array[] = {
(pfunc)_task_pipe_put_async, (pfunc)_task_pipe_put_async,
(pfunc)_task_pipe_put, (pfunc)_task_pipe_put,
(pfunc)_task_pipe_get, (pfunc)_task_pipe_get,
/* mailbox functions */ /* mailbox functions */
(pfunc)_task_mbox_put, (pfunc)_task_mbox_put,
(pfunc)_task_mbox_get, (pfunc)_task_mbox_get,
(pfunc)_task_mbox_put_async, (pfunc)_task_mbox_put_async,
(pfunc)_task_mbox_data_get, (pfunc)_task_mbox_data_get,
(pfunc)_task_mbox_data_get_async_block, (pfunc)_task_mbox_data_get_async_block,
/* memory pool functions */ /* memory pool functions */
(pfunc)_task_mem_pool_alloc, (pfunc)_task_mem_pool_alloc,
(pfunc)task_mem_pool_free, (pfunc)task_mem_pool_free,
(pfunc)task_mem_pool_defragment, (pfunc)task_mem_pool_defragment,
/* task functions */ /* task functions */
(pfunc)_task_ioctl, (pfunc)_task_ioctl,
(pfunc)_task_group_ioctl, (pfunc)_task_group_ioctl,
(pfunc)task_abort_handler_set, (pfunc)task_abort_handler_set,
@ -142,7 +142,7 @@ static pfunc func_array[] = {
(pfunc)task_sleep, (pfunc)task_sleep,
(pfunc)task_yield, (pfunc)task_yield,
#endif /* TEST_max */ #endif /* TEST_max */
}; };
/******************************************************************************* /*******************************************************************************
* *
@ -152,9 +152,9 @@ static pfunc func_array[] = {
*/ */
void dummyIsr(void *unused) void dummyIsr(void *unused)
{ {
ARG_UNUSED(unused); ARG_UNUSED(unused);
} }
#ifdef TEST_reg #ifdef TEST_reg
/******************************************************************************* /*******************************************************************************
@ -169,13 +169,13 @@ void dummyIsr(void *unused)
*/ */
static void isrDummyIntStub(void *unused) static void isrDummyIntStub(void *unused)
{ {
ARG_UNUSED(unused); ARG_UNUSED(unused);
isr_dummy(); isr_dummy();
CODE_UNREACHABLE; CODE_UNREACHABLE;
} }
#endif /* TEST_reg */ #endif /* TEST_reg */
/******************************************************************************* /*******************************************************************************
@ -191,14 +191,14 @@ static void isrDummyIntStub(void *unused)
*/ */
void fgTaskEntry(void) void fgTaskEntry(void)
{ {
#ifdef TEST_max #ifdef TEST_max
/* dynamically link in dummy ISR */ /* dynamically link in dummy ISR */
irq_connect(NANO_SOFT_IRQ, IRQ_PRIORITY, dummyIsr, irq_connect(NANO_SOFT_IRQ, IRQ_PRIORITY, dummyIsr,
(void *) 0, isrDummyHandlerStub); (void *) 0, isrDummyHandlerStub);
#endif /* TEST_max */ #endif /* TEST_max */
/* note: referencing "func_array" ensures it isn't optimized out */ /* note: referencing "func_array" ensures it isn't optimized out */
#ifdef TEST_max #ifdef TEST_max
printf((char *)MESSAGE, func_array); printf((char *)MESSAGE, func_array);
#else #else
@ -206,8 +206,8 @@ void fgTaskEntry(void)
#endif /* TEST_max */ #endif /* TEST_max */
while (1) { while (1) {
i++; i++;
}
} }
}
#endif /* TEST_min */ #endif /* TEST_min */

View file

@ -42,7 +42,7 @@ static inline void isr_dummy(void)
extern void _IntEnt(void); extern void _IntEnt(void);
extern void _IntExit(void); extern void _IntExit(void);
/* compiler-generated preamble pushes & modifies EBP */ /* compiler-generated preamble pushes & modifies EBP */
__asm__ volatile ( __asm__ volatile (
"pop %%ebp;\n\t" "pop %%ebp;\n\t"
"call _IntEnt;\n\t" "call _IntEnt;\n\t"

View file

@ -54,7 +54,7 @@ int errorCount = 0; /* track number of errors */
*/ */
void nanoTest(void) void nanoTest(void)
{ {
PRINT_NANO_BANNER(); PRINT_NANO_BANNER();
PRINT_TIME_BANNER(); PRINT_TIME_BANNER();
@ -72,7 +72,7 @@ void nanoTest(void)
nanoIntLockUnlock(); nanoIntLockUnlock();
printDashLine(); printDashLine();
} }
#ifdef CONFIG_NANOKERNEL #ifdef CONFIG_NANOKERNEL
/******************************************************************************* /*******************************************************************************
@ -85,14 +85,14 @@ void nanoTest(void)
*/ */
void main(void) void main(void)
{ {
bench_test_init(); bench_test_init();
nanoTest(); nanoTest();
PRINT_END_BANNER(); PRINT_END_BANNER();
TC_END_REPORT(errorCount); TC_END_REPORT(errorCount);
} }
#else #else
@ -112,7 +112,7 @@ void microTaskSwitchYield(void);
*/ */
void microTest(void) void microTest(void)
{ {
PRINT_MICRO_BANNER(); PRINT_MICRO_BANNER();
PRINT_TIME_BANNER(); PRINT_TIME_BANNER();
@ -130,7 +130,7 @@ void microTest(void)
microTaskSwitchYield(); microTaskSwitchYield();
printDashLine(); printDashLine();
} }
/******************************************************************************* /*******************************************************************************
* *
@ -142,7 +142,7 @@ void microTest(void)
*/ */
void microMain(void) void microMain(void)
{ {
bench_test_init(); bench_test_init();
nanoTest(); nanoTest();
@ -150,5 +150,5 @@ void microMain(void)
PRINT_END_BANNER(); PRINT_END_BANNER();
TC_END_REPORT(errorCount); TC_END_REPORT(errorCount);
} }
#endif /* CONFIG_NANOKERNEL */ #endif /* CONFIG_NANOKERNEL */

View file

@ -58,12 +58,12 @@ static uint32_t timestamp;
*/ */
static void latencyTestIsr(void *unused) static void latencyTestIsr(void *unused)
{ {
ARG_UNUSED(unused); ARG_UNUSED(unused);
flagVar = 1; flagVar = 1;
timestamp = TIME_STAMP_DELTA_GET(0); timestamp = TIME_STAMP_DELTA_GET(0);
} }
/******************************************************************************* /*******************************************************************************
* *
@ -78,16 +78,17 @@ static void latencyTestIsr(void *unused)
*/ */
static void makeInt(void) static void makeInt(void)
{ {
initSwInterrupt(latencyTestIsr); initSwInterrupt(latencyTestIsr);
flagVar = 0; flagVar = 0;
raiseIntFunc(); raiseIntFunc();
if (flagVar != 1) { if (flagVar != 1) {
PRINT_FORMAT(" Flag variable has not changed. FAILED\n"); PRINT_FORMAT(" Flag variable has not changed. FAILED\n");
} }
else else {
timestamp = TIME_STAMP_DELTA_GET(timestamp); timestamp = TIME_STAMP_DELTA_GET(timestamp);
} }
}
/******************************************************************************* /*******************************************************************************
* *
@ -99,16 +100,16 @@ static void makeInt(void)
*/ */
int microIntToTask(void) int microIntToTask(void)
{ {
PRINT_FORMAT(" 1- Measure time to switch from ISR to back to" PRINT_FORMAT(" 1- Measure time to switch from ISR to back to"
" interrupted task"); " interrupted task");
TICK_SYNCH(); TICK_SYNCH();
makeInt(); makeInt();
if (flagVar == 1) { if (flagVar == 1) {
PRINT_FORMAT(" switching time is %lu tcs = %lu nsec", PRINT_FORMAT(" switching time is %lu tcs = %lu nsec",
timestamp, SYS_CLOCK_HW_CYCLES_TO_NS(timestamp)); timestamp, SYS_CLOCK_HW_CYCLES_TO_NS(timestamp));
} }
return 0; return 0;
} }
#endif /* MICROKERNEL */ #endif /* MICROKERNEL */

View file

@ -60,12 +60,12 @@ static uint32_t timestamp = 0;
*/ */
static void latencyTestIsr(void *unused) static void latencyTestIsr(void *unused)
{ {
ARG_UNUSED(unused); ARG_UNUSED(unused);
isr_event_send(EVENT0); isr_event_send(EVENT0);
timestamp = TIME_STAMP_DELTA_GET(0); timestamp = TIME_STAMP_DELTA_GET(0);
} }
/******************************************************************************* /*******************************************************************************
* *
@ -81,12 +81,12 @@ static void latencyTestIsr(void *unused)
*/ */
void microInt(void) void microInt(void)
{ {
task_sem_take_wait(INTSEMA); task_sem_take_wait(INTSEMA);
setSwInterrupt(latencyTestIsr); setSwInterrupt(latencyTestIsr);
raiseIntFunc(); raiseIntFunc();
task_suspend(task_id_get()); task_suspend(task_id_get());
} }
/******************************************************************************* /*******************************************************************************
* *
@ -98,16 +98,16 @@ void microInt(void)
*/ */
int microIntToTaskEvt(void) int microIntToTaskEvt(void)
{ {
PRINT_FORMAT(" 2- Measure time from ISR to executing a different task" PRINT_FORMAT(" 2- Measure time from ISR to executing a different task"
" (rescheduled)"); " (rescheduled)");
TICK_SYNCH(); TICK_SYNCH();
task_sem_give(INTSEMA); task_sem_give(INTSEMA);
task_event_recv_wait(EVENT0); task_event_recv_wait(EVENT0);
timestamp = TIME_STAMP_DELTA_GET(timestamp); timestamp = TIME_STAMP_DELTA_GET(timestamp);
PRINT_FORMAT(" switch time is %lu tcs = %lu nsec", PRINT_FORMAT(" switch time is %lu tcs = %lu nsec",
timestamp, SYS_CLOCK_HW_CYCLES_TO_NS(timestamp)); timestamp, SYS_CLOCK_HW_CYCLES_TO_NS(timestamp));
return 0; return 0;
} }
#endif /* CONFIG_MICROKERNEL */ #endif /* CONFIG_MICROKERNEL */

View file

@ -66,44 +66,44 @@ static uint32_t timestamp;
*/ */
int microSemaLockUnlock(void) int microSemaLockUnlock(void)
{ {
int i; int i;
PRINT_FORMAT(" 3- Measure average time to signal a sema then test" PRINT_FORMAT(" 3- Measure average time to signal a sema then test"
" that sema"); " that sema");
bench_test_start(); bench_test_start();
timestamp = TIME_STAMP_DELTA_GET(0); timestamp = TIME_STAMP_DELTA_GET(0);
for (i = SEMASTART; i <= SEMAEND; i++) { for (i = SEMASTART; i <= SEMAEND; i++) {
task_sem_give(i); task_sem_give(i);
} }
timestamp = TIME_STAMP_DELTA_GET(timestamp); timestamp = TIME_STAMP_DELTA_GET(timestamp);
if (bench_test_end() == 0) { if (bench_test_end() == 0) {
PRINT_FORMAT(" Average semaphore signal time %lu tcs = %lu nsec", PRINT_FORMAT(" Average semaphore signal time %lu tcs = %lu nsec",
timestamp / N_TEST_SEMA, timestamp / N_TEST_SEMA,
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(timestamp, N_TEST_SEMA)); SYS_CLOCK_HW_CYCLES_TO_NS_AVG(timestamp, N_TEST_SEMA));
} }
else { else {
errorCount++; errorCount++;
PRINT_OVERFLOW_ERROR(); PRINT_OVERFLOW_ERROR();
} }
bench_test_start(); bench_test_start();
timestamp = TIME_STAMP_DELTA_GET(0); timestamp = TIME_STAMP_DELTA_GET(0);
for (i = SEMASTART; i <= SEMAEND; i++) { for (i = SEMASTART; i <= SEMAEND; i++) {
task_sem_take_wait(i); task_sem_take_wait(i);
} }
timestamp = TIME_STAMP_DELTA_GET(timestamp); timestamp = TIME_STAMP_DELTA_GET(timestamp);
if (bench_test_end() == 0) { if (bench_test_end() == 0) {
PRINT_FORMAT(" Average semaphore test time %lu tcs = %lu nsec", PRINT_FORMAT(" Average semaphore test time %lu tcs = %lu nsec",
timestamp / N_TEST_SEMA, timestamp / N_TEST_SEMA,
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(timestamp, N_TEST_SEMA)); SYS_CLOCK_HW_CYCLES_TO_NS_AVG(timestamp, N_TEST_SEMA));
} }
else { else {
errorCount++; errorCount++;
PRINT_OVERFLOW_ERROR(); PRINT_OVERFLOW_ERROR();
} }
return 0; return 0;
} }
/******************************************************************************* /*******************************************************************************
* *
@ -118,28 +118,28 @@ int microSemaLockUnlock(void)
*/ */
int microMutexLockUnlock(void) int microMutexLockUnlock(void)
{ {
int i; int i;
PRINT_FORMAT(" 4- Measure average time to lock a mutex then" PRINT_FORMAT(" 4- Measure average time to lock a mutex then"
" unlock that mutex"); " unlock that mutex");
timestamp = TIME_STAMP_DELTA_GET(0); timestamp = TIME_STAMP_DELTA_GET(0);
for (i = 0; i < N_TEST_MUTEX; i++) { for (i = 0; i < N_TEST_MUTEX; i++) {
task_mutex_lock_wait(TEST_MUTEX); task_mutex_lock_wait(TEST_MUTEX);
} }
timestamp = TIME_STAMP_DELTA_GET(timestamp); timestamp = TIME_STAMP_DELTA_GET(timestamp);
PRINT_FORMAT(" Average time to lock the mutex %lu tcs = %lu nsec", PRINT_FORMAT(" Average time to lock the mutex %lu tcs = %lu nsec",
timestamp / N_TEST_MUTEX, timestamp / N_TEST_MUTEX,
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(timestamp, N_TEST_MUTEX)); SYS_CLOCK_HW_CYCLES_TO_NS_AVG(timestamp, N_TEST_MUTEX));
timestamp = TIME_STAMP_DELTA_GET(0); timestamp = TIME_STAMP_DELTA_GET(0);
for (i = 0; i <= N_TEST_MUTEX; i++) { for (i = 0; i <= N_TEST_MUTEX; i++) {
task_mutex_unlock(TEST_MUTEX); task_mutex_unlock(TEST_MUTEX);
} }
timestamp = TIME_STAMP_DELTA_GET(timestamp); timestamp = TIME_STAMP_DELTA_GET(timestamp);
PRINT_FORMAT(" Average time to unlock the mutex %lu tcs = %lu nsec", PRINT_FORMAT(" Average time to unlock the mutex %lu tcs = %lu nsec",
timestamp / N_TEST_MUTEX, timestamp / N_TEST_MUTEX,
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(timestamp, N_TEST_MUTEX)); SYS_CLOCK_HW_CYCLES_TO_NS_AVG(timestamp, N_TEST_MUTEX));
return 0; return 0;
} }
#endif /* CONFIG_MICROKERNEL */ #endif /* CONFIG_MICROKERNEL */

View file

@ -62,12 +62,12 @@ static uint32_t helper_task_iterations = 0;
*/ */
void yieldingTask(void) void yieldingTask(void)
{ {
while (helper_task_iterations < NB_OF_YIELD) { while (helper_task_iterations < NB_OF_YIELD) {
task_yield(); task_yield();
helper_task_iterations++; helper_task_iterations++;
}
} }
}
/******************************************************************************* /*******************************************************************************
* *
@ -79,60 +79,60 @@ void yieldingTask(void)
*/ */
void microTaskSwitchYield(void) void microTaskSwitchYield(void)
{ {
uint32_t iterations = 0; uint32_t iterations = 0;
int32_t delta; int32_t delta;
uint32_t timestamp; uint32_t timestamp;
PRINT_FORMAT(" 5- Measure average context switch time between tasks using" PRINT_FORMAT(" 5- Measure average context switch time between tasks using"
" (task_yield)"); " (task_yield)");
bench_test_start(); bench_test_start();
/* launch helper task of the same priority than this routine */ /* launch helper task of the same priority than this routine */
task_start(YIELDTASK); task_start(YIELDTASK);
/* get initial timestamp */ /* get initial timestamp */
timestamp = TIME_STAMP_DELTA_GET(0); timestamp = TIME_STAMP_DELTA_GET(0);
/* loop until either helper or this routine reaches number of yields */ /* loop until either helper or this routine reaches number of yields */
while (iterations < NB_OF_YIELD && helper_task_iterations < NB_OF_YIELD) { while (iterations < NB_OF_YIELD && helper_task_iterations < NB_OF_YIELD) {
task_yield(); task_yield();
iterations++; iterations++;
} }
/* get the number of cycles it took to do the test */ /* get the number of cycles it took to do the test */
timestamp = TIME_STAMP_DELTA_GET(timestamp); timestamp = TIME_STAMP_DELTA_GET(timestamp);
/* Ensure both helper and this routine were context switching back & forth. /* Ensure both helper and this routine were context switching back & forth.
* For execution to reach the line below, either this routine or helper * For execution to reach the line below, either this routine or helper
* routine reached NB_OF_YIELD. The other loop must be at most one * routine reached NB_OF_YIELD. The other loop must be at most one
* iteration away from reaching NB_OF_YIELD if execute was switching back * iteration away from reaching NB_OF_YIELD if execute was switching back
* and forth. * and forth.
*/ */
delta = iterations - helper_task_iterations; delta = iterations - helper_task_iterations;
if (bench_test_end() < 0) { if (bench_test_end() < 0) {
errorCount++; errorCount++;
PRINT_OVERFLOW_ERROR(); PRINT_OVERFLOW_ERROR();
} }
else if (abs(delta) > 1) { else if (abs(delta) > 1) {
/* expecting even alternating context switch, seems one routine /* expecting even alternating context switch, seems one routine
* called yield without the other having chance to execute * called yield without the other having chance to execute
*/ */
errorCount++; errorCount++;
PRINT_FORMAT(" Error, iteration:%lu, helper iteration:%lu", PRINT_FORMAT(" Error, iteration:%lu, helper iteration:%lu",
iterations, helper_task_iterations); iterations, helper_task_iterations);
} }
else { else {
/* task_yield is called (iterations + helper_task_iterations) /* task_yield is called (iterations + helper_task_iterations)
* times in total. * times in total.
*/ */
PRINT_FORMAT(" Average task context switch using " PRINT_FORMAT(" Average task context switch using "
"yield %lu tcs = %lu nsec", "yield %lu tcs = %lu nsec",
timestamp / (iterations + helper_task_iterations), timestamp / (iterations + helper_task_iterations),
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(timestamp, SYS_CLOCK_HW_CYCLES_TO_NS_AVG(timestamp,
(iterations + helper_task_iterations))); (iterations + helper_task_iterations)));
}
} }
}
#endif #endif

View file

@ -77,16 +77,16 @@ static volatile int ctxSwitchBalancer = 0;
*/ */
static void fiberOne(void) static void fiberOne(void)
{ {
nano_fiber_sem_take_wait(&syncSema); nano_fiber_sem_take_wait(&syncSema);
timestamp = TIME_STAMP_DELTA_GET(0); timestamp = TIME_STAMP_DELTA_GET(0);
while (ctxSwitchCounter < NCTXSWITCH) { while (ctxSwitchCounter < NCTXSWITCH) {
fiber_yield(); fiber_yield();
ctxSwitchCounter++; ctxSwitchCounter++;
ctxSwitchBalancer--; ctxSwitchBalancer--;
} }
timestamp = TIME_STAMP_DELTA_GET(timestamp); timestamp = TIME_STAMP_DELTA_GET(timestamp);
} }
/******************************************************************************* /*******************************************************************************
* *
@ -101,14 +101,14 @@ static void fiberOne(void)
*/ */
static void fiberTwo(void) static void fiberTwo(void)
{ {
nano_fiber_sem_give(&syncSema); nano_fiber_sem_give(&syncSema);
while (ctxSwitchCounter < NCTXSWITCH) { while (ctxSwitchCounter < NCTXSWITCH) {
fiber_yield(); fiber_yield();
ctxSwitchCounter++; ctxSwitchCounter++;
ctxSwitchBalancer++; ctxSwitchBalancer++;
}
} }
}
/******************************************************************************* /*******************************************************************************
* *
@ -120,7 +120,7 @@ static void fiberTwo(void)
*/ */
int nanoCtxSwitch(void) int nanoCtxSwitch(void)
{ {
PRINT_FORMAT(" 4- Measure average context switch time between fibers"); PRINT_FORMAT(" 4- Measure average context switch time between fibers");
nano_sem_init(&syncSema); nano_sem_init(&syncSema);
ctxSwitchCounter = 0; ctxSwitchCounter = 0;
@ -128,19 +128,20 @@ int nanoCtxSwitch(void)
bench_test_start(); bench_test_start();
task_fiber_start(&fiberOneStack[0], STACKSIZE, task_fiber_start(&fiberOneStack[0], STACKSIZE,
(nano_fiber_entry_t) fiberOne, 0, 0, 6, 0); (nano_fiber_entry_t) fiberOne, 0, 0, 6, 0);
task_fiber_start(&fiberTwoStack[0], STACKSIZE, task_fiber_start(&fiberTwoStack[0], STACKSIZE,
(nano_fiber_entry_t) fiberTwo, 0, 0, 6, 0); (nano_fiber_entry_t) fiberTwo, 0, 0, 6, 0);
if (ctxSwitchBalancer > 3 || ctxSwitchBalancer < -3) { if (ctxSwitchBalancer > 3 || ctxSwitchBalancer < -3) {
PRINT_FORMAT(" Balance is %d. FAILED", ctxSwitchBalancer); PRINT_FORMAT(" Balance is %d. FAILED", ctxSwitchBalancer);
} }
else if (bench_test_end() != 0) { else if (bench_test_end() != 0) {
errorCount++; errorCount++;
PRINT_OVERFLOW_ERROR(); PRINT_OVERFLOW_ERROR();
}
else {
PRINT_FORMAT(" Average context switch time is %lu tcs = %lu nsec",
timestamp / ctxSwitchCounter,
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(timestamp, ctxSwitchCounter));
} }
else
PRINT_FORMAT(" Average context switch time is %lu tcs = %lu nsec",
timestamp / ctxSwitchCounter,
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(timestamp, ctxSwitchCounter));
return 0; return 0;
} }

View file

@ -60,11 +60,11 @@ static uint32_t timestamp;
*/ */
static void latencyTestIsr(void *unused) static void latencyTestIsr(void *unused)
{ {
ARG_UNUSED(unused); ARG_UNUSED(unused);
timestamp = TIME_STAMP_DELTA_GET(timestamp); timestamp = TIME_STAMP_DELTA_GET(timestamp);
} }
/******************************************************************************* /*******************************************************************************
* *
@ -79,11 +79,11 @@ static void latencyTestIsr(void *unused)
*/ */
static void fiberInt(void) static void fiberInt(void)
{ {
initSwInterrupt(latencyTestIsr); initSwInterrupt(latencyTestIsr);
timestamp = TIME_STAMP_DELTA_GET(0); timestamp = TIME_STAMP_DELTA_GET(0);
raiseIntFunc(); raiseIntFunc();
} }
/******************************************************************************* /*******************************************************************************
* *
@ -95,12 +95,12 @@ static void fiberInt(void)
*/ */
int nanoIntLatency(void) int nanoIntLatency(void)
{ {
PRINT_FORMAT(" 1- Measure time to switch from fiber to ISR execution"); PRINT_FORMAT(" 1- Measure time to switch from fiber to ISR execution");
TICK_SYNCH(); TICK_SYNCH();
task_fiber_start(&fiberStack[0], STACKSIZE, task_fiber_start(&fiberStack[0], STACKSIZE,
(nano_fiber_entry_t) fiberInt, 0, 0, 6, 0); (nano_fiber_entry_t) fiberInt, 0, 0, 6, 0);
PRINT_FORMAT(" switching time is %lu tcs = %lu nsec", PRINT_FORMAT(" switching time is %lu tcs = %lu nsec",
timestamp, SYS_CLOCK_HW_CYCLES_TO_NS(timestamp)); timestamp, SYS_CLOCK_HW_CYCLES_TO_NS(timestamp));
return 0; return 0;
} }

View file

@ -59,48 +59,48 @@ static uint32_t timestamp = 0;
*/ */
int nanoIntLockUnlock(void) int nanoIntLockUnlock(void)
{ {
int i; int i;
unsigned int mask; unsigned int mask;
PRINT_FORMAT(" 5- Measure average time to lock then unlock interrupts"); PRINT_FORMAT(" 5- Measure average time to lock then unlock interrupts");
PRINT_FORMAT(" 5.1- When each lock and unlock is executed as a function" PRINT_FORMAT(" 5.1- When each lock and unlock is executed as a function"
" call"); " call");
bench_test_start(); bench_test_start();
timestamp = TIME_STAMP_DELTA_GET(0); timestamp = TIME_STAMP_DELTA_GET(0);
for (i = 0; i < NTESTS; i++) { for (i = 0; i < NTESTS; i++) {
mask = irq_lock(); mask = irq_lock();
irq_unlock(mask); irq_unlock(mask);
} }
timestamp = TIME_STAMP_DELTA_GET(timestamp); timestamp = TIME_STAMP_DELTA_GET(timestamp);
if (bench_test_end() == 0) { if (bench_test_end() == 0) {
PRINT_FORMAT(" Average time for lock then unlock " PRINT_FORMAT(" Average time for lock then unlock "
"is %lu tcs = %lu nsec", "is %lu tcs = %lu nsec",
timestamp / NTESTS, SYS_CLOCK_HW_CYCLES_TO_NS_AVG(timestamp, NTESTS)); timestamp / NTESTS, SYS_CLOCK_HW_CYCLES_TO_NS_AVG(timestamp, NTESTS));
} }
else { else {
errorCount++; errorCount++;
PRINT_OVERFLOW_ERROR(); PRINT_OVERFLOW_ERROR();
} }
PRINT_FORMAT(" "); PRINT_FORMAT(" ");
PRINT_FORMAT(" 5.2- When each lock and unlock is executed as inline" PRINT_FORMAT(" 5.2- When each lock and unlock is executed as inline"
" function call"); " function call");
bench_test_start(); bench_test_start();
timestamp = TIME_STAMP_DELTA_GET(0); timestamp = TIME_STAMP_DELTA_GET(0);
for (i = 0; i < NTESTS; i++) { for (i = 0; i < NTESTS; i++) {
mask = irq_lock_inline(); mask = irq_lock_inline();
irq_unlock_inline(mask); irq_unlock_inline(mask);
} }
timestamp = TIME_STAMP_DELTA_GET(timestamp); timestamp = TIME_STAMP_DELTA_GET(timestamp);
if (bench_test_end() == 0) { if (bench_test_end() == 0) {
PRINT_FORMAT(" Average time for lock then unlock " PRINT_FORMAT(" Average time for lock then unlock "
"is %lu tcs = %lu nsec", "is %lu tcs = %lu nsec",
timestamp / NTESTS, SYS_CLOCK_HW_CYCLES_TO_NS_AVG(timestamp, NTESTS)); timestamp / NTESTS, SYS_CLOCK_HW_CYCLES_TO_NS_AVG(timestamp, NTESTS));
} }
else { else {
errorCount++; errorCount++;
PRINT_OVERFLOW_ERROR(); PRINT_OVERFLOW_ERROR();
} }
return 0; return 0;
} }

View file

@ -62,12 +62,12 @@ static uint32_t timestamp;
*/ */
static void latencyTestIsr(void *unused) static void latencyTestIsr(void *unused)
{ {
ARG_UNUSED(unused); ARG_UNUSED(unused);
flagVar = 1; flagVar = 1;
timestamp = TIME_STAMP_DELTA_GET(0); timestamp = TIME_STAMP_DELTA_GET(0);
} }
/******************************************************************************* /*******************************************************************************
* *
@ -82,16 +82,17 @@ static void latencyTestIsr(void *unused)
*/ */
static void fiberInt(void) static void fiberInt(void)
{ {
setSwInterrupt(latencyTestIsr); setSwInterrupt(latencyTestIsr);
flagVar = 0; flagVar = 0;
raiseIntFunc(); raiseIntFunc();
if (flagVar != 1) { if (flagVar != 1) {
PRINT_FORMAT(" Flag variable has not changed. FAILED"); PRINT_FORMAT(" Flag variable has not changed. FAILED");
} }
else else {
timestamp = TIME_STAMP_DELTA_GET(timestamp); timestamp = TIME_STAMP_DELTA_GET(timestamp);
} }
}
/******************************************************************************* /*******************************************************************************
* *
@ -103,15 +104,15 @@ static void fiberInt(void)
*/ */
int nanoIntToFiber(void) int nanoIntToFiber(void)
{ {
PRINT_FORMAT(" 2- Measure time to switch from ISR back to interrupted" PRINT_FORMAT(" 2- Measure time to switch from ISR back to interrupted"
" fiber"); " fiber");
TICK_SYNCH(); TICK_SYNCH();
task_fiber_start(&fiberStack[0], STACKSIZE, task_fiber_start(&fiberStack[0], STACKSIZE,
(nano_fiber_entry_t) fiberInt, 0, 0, 6, 0); (nano_fiber_entry_t) fiberInt, 0, 0, 6, 0);
if (flagVar == 1) { if (flagVar == 1) {
PRINT_FORMAT(" switching time is %lu tcs = %lu nsec", PRINT_FORMAT(" switching time is %lu tcs = %lu nsec",
timestamp, SYS_CLOCK_HW_CYCLES_TO_NS(timestamp)); timestamp, SYS_CLOCK_HW_CYCLES_TO_NS(timestamp));
} }
return 0; return 0;
} }

View file

@ -73,12 +73,12 @@ static uint32_t timestamp = 0;
*/ */
static void latencyTestIsr(void *unused) static void latencyTestIsr(void *unused)
{ {
ARG_UNUSED(unused); ARG_UNUSED(unused);
nano_isr_sem_give(&testSema); nano_isr_sem_give(&testSema);
timestamp = TIME_STAMP_DELTA_GET(0); timestamp = TIME_STAMP_DELTA_GET(0);
} }
/******************************************************************************* /*******************************************************************************
* *
@ -93,11 +93,11 @@ static void latencyTestIsr(void *unused)
*/ */
static void fiberInt(void) static void fiberInt(void)
{ {
setSwInterrupt(latencyTestIsr); setSwInterrupt(latencyTestIsr);
raiseIntFunc(); raiseIntFunc();
fiber_yield(); fiber_yield();
} }
/******************************************************************************* /*******************************************************************************
* *
@ -112,10 +112,10 @@ static void fiberInt(void)
*/ */
static void fiberWaiter(void) static void fiberWaiter(void)
{ {
nano_fiber_sem_take_wait(&testSema); nano_fiber_sem_take_wait(&testSema);
timestamp = TIME_STAMP_DELTA_GET(timestamp); timestamp = TIME_STAMP_DELTA_GET(timestamp);
} }
/******************************************************************************* /*******************************************************************************
* *
@ -127,18 +127,18 @@ static void fiberWaiter(void)
*/ */
int nanoIntToFiberSem(void) int nanoIntToFiberSem(void)
{ {
PRINT_FORMAT(" 3- Measure time from ISR to executing a different fiber" PRINT_FORMAT(" 3- Measure time from ISR to executing a different fiber"
" (rescheduled)"); " (rescheduled)");
nano_sem_init(&testSema); nano_sem_init(&testSema);
TICK_SYNCH(); TICK_SYNCH();
task_fiber_start(&waiterStack[0], STACKSIZE, task_fiber_start(&waiterStack[0], STACKSIZE,
(nano_fiber_entry_t) fiberWaiter, 0, 0, 5, 0); (nano_fiber_entry_t) fiberWaiter, 0, 0, 5, 0);
task_fiber_start(&intStack[0], STACKSIZE, task_fiber_start(&intStack[0], STACKSIZE,
(nano_fiber_entry_t) fiberInt, 0, 0, 6, 0); (nano_fiber_entry_t) fiberInt, 0, 0, 6, 0);
PRINT_FORMAT(" switching time is %lu tcs = %lu nsec", PRINT_FORMAT(" switching time is %lu tcs = %lu nsec",
timestamp, SYS_CLOCK_HW_CYCLES_TO_NS(timestamp)); timestamp, SYS_CLOCK_HW_CYCLES_TO_NS(timestamp));
return 0; return 0;
} }

View file

@ -85,29 +85,30 @@ typedef int64_t TICK_TYPE;
extern uint32_t tm_off; extern uint32_t tm_off;
static inline uint32_t TIME_STAMP_DELTA_GET(uint32_t ts) static inline uint32_t TIME_STAMP_DELTA_GET(uint32_t ts)
{ {
uint32_t t; uint32_t t;
/* serialize so OS_GET_TIME() is not reordered */ /* serialize so OS_GET_TIME() is not reordered */
timestamp_serialize(); timestamp_serialize();
t = OS_GET_TIME(); t = OS_GET_TIME();
uint32_t res = (t >= ts)? (t - ts): (ULONG_MAX - ts + t); uint32_t res = (t >= ts)? (t - ts): (ULONG_MAX - ts + t);
if (ts > 0) if (ts > 0) {
res -= tm_off; res -= tm_off;
return res;
} }
return res;
}
/* /*
* Routine initializes the benchmark timing measurement * Routine initializes the benchmark timing measurement
* The function sets up the global variable tm_off * The function sets up the global variable tm_off
*/ */
static inline void bench_test_init(void) static inline void bench_test_init(void)
{ {
uint32_t t = OS_GET_TIME(); uint32_t t = OS_GET_TIME();
tm_off = OS_GET_TIME() - t; tm_off = OS_GET_TIME() - t;
} }
#if defined(CONFIG_MICROKERNEL) && defined(KERNEL) #if defined(CONFIG_MICROKERNEL) && defined(KERNEL)
@ -127,23 +128,23 @@ static TICK_TYPE tCheck;
* Functions modify the tCheck global variable. * Functions modify the tCheck global variable.
*/ */
static inline void bench_test_start(void) static inline void bench_test_start(void)
{ {
tCheck = 0; tCheck = 0;
/* before reading time we synchronize to the start of the timer tick */ /* before reading time we synchronize to the start of the timer tick */
TICK_SYNCH(); TICK_SYNCH();
tCheck = TICK_GET(&tCheck); tCheck = TICK_GET(&tCheck);
} }
/* returns 0 if the number of ticks is valid and -1 if not */ /* returns 0 if the number of ticks is valid and -1 if not */
static inline int bench_test_end(void) static inline int bench_test_end(void)
{ {
tCheck = TICK_GET(&tCheck); tCheck = TICK_GET(&tCheck);
if (tCheck > BENCH_MAX_TICKS) if (tCheck > BENCH_MAX_TICKS) {
return -1; return -1;
else
return 0;
} }
return 0;
}
/* /*
* Returns -1 if number of ticks cause high precision timer counter * Returns -1 if number of ticks cause high precision timer counter
@ -152,12 +153,12 @@ static inline int bench_test_end(void)
* results or is it completely invalid * results or is it completely invalid
*/ */
static inline int high_timer_overflow(void) static inline int high_timer_overflow(void)
{ {
if (tCheck >= (UINT_MAX / sys_clock_hw_cycles_per_tick)) if (tCheck >= (UINT_MAX / sys_clock_hw_cycles_per_tick)) {
return -1; return -1;
else
return 0;
} }
return 0;
}
#endif /* CONFIG_NANOKERNEL || CONFIG_MICROKERNEL */ #endif /* CONFIG_NANOKERNEL || CONFIG_MICROKERNEL */
#endif /* _TIMESTAMP_H_ */ #endif /* _TIMESTAMP_H_ */

View file

@ -73,13 +73,13 @@ char tmpString[TMP_STRING_SIZE];
*/ */
int initSwInterrupt(ptestIsr pIsrHdlr) int initSwInterrupt(ptestIsr pIsrHdlr)
{ {
vector = irq_connect(NANO_SOFT_IRQ, IRQ_PRIORITY, pIsrHdlr, vector = irq_connect(NANO_SOFT_IRQ, IRQ_PRIORITY, pIsrHdlr,
(void *) 0, isrLatencyHandlerStub); (void *) 0, isrLatencyHandlerStub);
pcurrIsrFunc = pIsrHdlr; pcurrIsrFunc = pIsrHdlr;
return vector; return vector;
} }
/******************************************************************************* /*******************************************************************************
* *
@ -95,10 +95,10 @@ int initSwInterrupt(ptestIsr pIsrHdlr)
*/ */
void setSwInterrupt(ptestIsr pIsrHdlr) void setSwInterrupt(ptestIsr pIsrHdlr)
{ {
irq_handler_set(vector, pcurrIsrFunc, pIsrHdlr, (void *)0); irq_handler_set(vector, pcurrIsrFunc, pIsrHdlr, (void *)0);
pcurrIsrFunc = pIsrHdlr; pcurrIsrFunc = pIsrHdlr;
} }
/******************************************************************************* /*******************************************************************************
* *
@ -114,6 +114,6 @@ void setSwInterrupt(ptestIsr pIsrHdlr)
* \NOMANUAL * \NOMANUAL
*/ */
void raiseIntFunc(void) void raiseIntFunc(void)
{ {
raiseInt(vector); raiseInt(vector);
} }

View file

@ -51,13 +51,11 @@ extern int errorCount;
#define PRINT(fmt, ...) printk(fmt, ##__VA_ARGS__) #define PRINT(fmt, ...) printk(fmt, ##__VA_ARGS__)
#define PRINTF(fmt, ...) printf(fmt, ##__VA_ARGS__) #define PRINTF(fmt, ...) printf(fmt, ##__VA_ARGS__)
#define PRINT_FORMAT(fmt, ...) \ #define PRINT_FORMAT(fmt, ...) \
do \ do { \
{ \
snprintf(tmpString, TMP_STRING_SIZE, fmt, ##__VA_ARGS__); \ snprintf(tmpString, TMP_STRING_SIZE, fmt, ##__VA_ARGS__); \
PRINTF("|%-77s|\n", tmpString); \ PRINTF("|%-77s|\n", tmpString); \
} \ } while (0)
while (0)
/******************************************************************************* /*******************************************************************************
* *
@ -69,33 +67,34 @@ extern int errorCount;
*/ */
static inline void printDashLine(void) static inline void printDashLine(void)
{ {
PRINTF("|-----------------------------------------------------------------" PRINTF("|-----------------------------------------------------------------"
"------------|\n"); "------------|\n");
} }
#define PRINT_END_BANNER() \ #define PRINT_END_BANNER() \
PRINTF("| E N D "\ PRINTF("| E N D "\
" |\n"); \ " |\n"); \
printDashLine(); printDashLine();
#define PRINT_NANO_BANNER() \ #define PRINT_NANO_BANNER() \
printDashLine(); \ printDashLine(); \
PRINTF("| VxMicro Nanokernel Latency Benchmark "\ PRINTF("| VxMicro Nanokernel Latency Benchmark "\
" |\n"); \ " |\n"); \
printDashLine(); printDashLine();
#define PRINT_MICRO_BANNER() \ #define PRINT_MICRO_BANNER() \
printDashLine(); \ printDashLine(); \
PRINTF("| VxMicro Microkernel Latency Benchmark "\ PRINTF("| VxMicro Microkernel Latency Benchmark "\
" |\n"); \ " |\n"); \
printDashLine(); printDashLine();
#define PRINT_TIME_BANNER() \ #define PRINT_TIME_BANNER() \
PRINT_FORMAT(" tcs = timer clock cycles: 1 tcs is %lu nsec", SYS_CLOCK_HW_CYCLES_TO_NS(1));\ PRINT_FORMAT(" tcs = timer clock cycles: 1 tcs is %lu nsec", \
SYS_CLOCK_HW_CYCLES_TO_NS(1)); \
printDashLine(); printDashLine();
#define PRINT_OVERFLOW_ERROR() \ #define PRINT_OVERFLOW_ERROR() \
PRINT_FORMAT(" Error: tick occured") PRINT_FORMAT(" Error: tick occured")
#else #else

View file

@ -87,7 +87,7 @@ uint32_t criticalLoop(uint32_t count)
while (task_tick_get_32() < ticks + NUM_TICKS) { while (task_tick_get_32() < ticks + NUM_TICKS) {
task_offload_to_fiber(criticalRtn, &criticalVar); task_offload_to_fiber(criticalRtn, &criticalVar);
count++; count++;
} }
return count; return count;
} }
@ -138,18 +138,18 @@ void RegressionTask(void)
nCalls = criticalLoop(nCalls); nCalls = criticalLoop(nCalls);
/* Wait for AlternateTask() to complete */ /* Wait for AlternateTask() to complete */
status = task_sem_take_wait_timeout(REGRESS_SEM, TEST_TIMEOUT); status = task_sem_take_wait_timeout(REGRESS_SEM, TEST_TIMEOUT);
if (status != RC_OK) { if (status != RC_OK) {
TC_ERROR("Timed out waiting for REGRESS_SEM\n"); TC_ERROR("Timed out waiting for REGRESS_SEM\n");
goto errorReturn; goto errorReturn;
} }
if (criticalVar != nCalls + altTaskIterations) { if (criticalVar != nCalls + altTaskIterations) {
TC_ERROR("Unexpected value for <criticalVar>. Expected %d, got %d\n", TC_ERROR("Unexpected value for <criticalVar>. Expected %d, got %d\n",
nCalls + altTaskIterations, criticalVar); nCalls + altTaskIterations, criticalVar);
goto errorReturn; goto errorReturn;
} }
TC_PRINT("Obtained expected <criticalVar> value of %u\n", criticalVar); TC_PRINT("Obtained expected <criticalVar> value of %u\n", criticalVar);
TC_PRINT("Enabling time slicing ...\n"); TC_PRINT("Enabling time slicing ...\n");
@ -160,18 +160,18 @@ void RegressionTask(void)
nCalls = criticalLoop(nCalls); nCalls = criticalLoop(nCalls);
/* Wait for AlternateTask() to finish */ /* Wait for AlternateTask() to finish */
status = task_sem_take_wait_timeout(REGRESS_SEM, TEST_TIMEOUT); status = task_sem_take_wait_timeout(REGRESS_SEM, TEST_TIMEOUT);
if (status != RC_OK) { if (status != RC_OK) {
TC_ERROR("Timed out waiting for REGRESS_SEM\n"); TC_ERROR("Timed out waiting for REGRESS_SEM\n");
goto errorReturn; goto errorReturn;
} }
if (criticalVar != nCalls + altTaskIterations) { if (criticalVar != nCalls + altTaskIterations) {
TC_ERROR("Unexpected value for <criticalVar>. Expected %d, got %d\n", TC_ERROR("Unexpected value for <criticalVar>. Expected %d, got %d\n",
nCalls + altTaskIterations, criticalVar); nCalls + altTaskIterations, criticalVar);
goto errorReturn; goto errorReturn;
} }
TC_PRINT("Obtained expected <criticalVar> value of %u\n", criticalVar); TC_PRINT("Obtained expected <criticalVar> value of %u\n", criticalVar);
TC_END_RESULT(TC_PASS); TC_END_RESULT(TC_PASS);

View file

@ -64,27 +64,27 @@ static char fiberStack[FIBER_STACK_SIZE]; /* test fiber stack size */
* RETURNS: N/A * RETURNS: N/A
*/ */
static void testFiberEntry(void) static void testFiberEntry(void)
{ {
/* signal event for eventWaitTest() */ /* signal event for eventWaitTest() */
/* single test */ /* single test */
nano_fiber_sem_take_wait(&fiberSem); nano_fiber_sem_take_wait(&fiberSem);
fiber_event_send(EVENT_ID); fiber_event_send(EVENT_ID);
/* test in cycle */ /* test in cycle */
nano_fiber_sem_take_wait(&fiberSem); nano_fiber_sem_take_wait(&fiberSem);
fiber_event_send(EVENT_ID); fiber_event_send(EVENT_ID);
/* signal event for eventTimeoutTest() */ /* signal event for eventTimeoutTest() */
nano_fiber_sem_take_wait(&fiberSem); nano_fiber_sem_take_wait(&fiberSem);
fiber_event_send(EVENT_ID); fiber_event_send(EVENT_ID);
/* /*
* Signal two events for fiberEventSignalTest (). * Signal two events for fiberEventSignalTest ().
* It has to detect only one * It has to detect only one
*/ */
nano_fiber_sem_take_wait(&fiberSem); nano_fiber_sem_take_wait(&fiberSem);
fiber_event_send(EVENT_ID); fiber_event_send(EVENT_ID);
fiber_event_send(EVENT_ID); fiber_event_send(EVENT_ID);
} }
/******************************************************************************* /*******************************************************************************
* *
@ -94,8 +94,8 @@ static void testFiberEntry(void)
*/ */
void testFiberInit(void) void testFiberInit(void)
{ {
nano_sem_init(&fiberSem); nano_sem_init(&fiberSem);
task_fiber_start(fiberStack, FIBER_STACK_SIZE, (nano_fiber_entry_t)testFiberEntry, task_fiber_start(fiberStack, FIBER_STACK_SIZE, (nano_fiber_entry_t)testFiberEntry,
0, 0, FIBER_PRIORITY, 0); 0, 0, FIBER_PRIORITY, 0);
} }

View file

@ -207,8 +207,9 @@ void load_store_low(void)
*/ */
floatRegInitByte = MAIN_FLOAT_REG_CHECK_BYTE; floatRegInitByte = MAIN_FLOAT_REG_CHECK_BYTE;
for (bufIx = 0; bufIx < SIZEOF_FP_REG_SET; ++bufIx) for (bufIx = 0; bufIx < SIZEOF_FP_REG_SET; ++bufIx) {
((unsigned char *)&floatRegSetLoad)[bufIx] = floatRegInitByte++; ((unsigned char *)&floatRegSetLoad)[bufIx] = floatRegInitByte++;
}
/* Keep cranking forever, or until an error is detected. */ /* Keep cranking forever, or until an error is detected. */
@ -353,8 +354,9 @@ void load_store_high(void)
floatRegInitByte = FIBER_FLOAT_REG_CHECK_BYTE; floatRegInitByte = FIBER_FLOAT_REG_CHECK_BYTE;
for (bufIx = 0; bufIx < SIZEOF_FP_REG_SET; ++bufIx) for (bufIx = 0; bufIx < SIZEOF_FP_REG_SET; ++bufIx) {
floatRegisterSetBytePtr[bufIx] = floatRegInitByte++; floatRegisterSetBytePtr[bufIx] = floatRegInitByte++;
}
/* /*
* Utilize an architecture specific function to load all the floating * Utilize an architecture specific function to load all the floating
@ -395,9 +397,10 @@ void load_store_high(void)
/* periodically issue progress report */ /* periodically issue progress report */
if ((++load_store_high_count % 100) == 0) if ((++load_store_high_count % 100) == 0) {
PRINT_DATA("Load and store OK after %u (high) + %u (low) tests\n", PRINT_DATA("Load and store OK after %u (high) + %u (low) tests\n",
load_store_high_count, load_store_low_count); load_store_high_count, load_store_low_count);
}
#if (MAX_TESTS != 0) #if (MAX_TESTS != 0)
/* terminate testing if specified limit has been reached */ /* terminate testing if specified limit has been reached */

View file

@ -165,15 +165,15 @@ char buffer[BUFSIZE];
int memset_test(void) int memset_test(void)
{ {
TC_PRINT ("\tmemset ...\t"); TC_PRINT("\tmemset ...\t");
memset (buffer, 'a', BUFSIZE); memset(buffer, 'a', BUFSIZE);
if (buffer[0] != 'a' || buffer[BUFSIZE-1] != 'a') { if (buffer[0] != 'a' || buffer[BUFSIZE-1] != 'a') {
TC_PRINT ("failed\n"); TC_PRINT("failed\n");
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT ("passed\n"); TC_PRINT("passed\n");
return TC_PASS; return TC_PASS;
} }
@ -186,16 +186,16 @@ int memset_test(void)
int strlen_test(void) int strlen_test(void)
{ {
TC_PRINT ("\tstrlen ...\t"); TC_PRINT("\tstrlen ...\t");
memset (buffer, '\0', BUFSIZE); memset(buffer, '\0', BUFSIZE);
memset (buffer, 'b', 5); /* 5 is BUFSIZE / 2 */ memset(buffer, 'b', 5); /* 5 is BUFSIZE / 2 */
if (strlen(buffer) != 5) { if (strlen(buffer) != 5) {
TC_PRINT ("failed\n"); TC_PRINT("failed\n");
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT ("passed\n"); TC_PRINT("passed\n");
return TC_PASS; return TC_PASS;
} }
@ -206,32 +206,32 @@ int strlen_test(void)
* RETURNS: TC_PASS or TC_FAIL * RETURNS: TC_PASS or TC_FAIL
*/ */
int strcmp_test (void) int strcmp_test(void)
{ {
strcpy(buffer, "eeeee"); strcpy(buffer, "eeeee");
TC_PRINT ("\tstrcmp less ...\t"); TC_PRINT("\tstrcmp less ...\t");
if (strcmp(buffer, "fffff") >= 0) { if (strcmp(buffer, "fffff") >= 0) {
TC_PRINT ("failed\n"); TC_PRINT("failed\n");
return TC_FAIL; return TC_FAIL;
} else { } else {
TC_PRINT ("passed\n"); TC_PRINT("passed\n");
} }
TC_PRINT ("\tstrcmp equal ...\t"); TC_PRINT("\tstrcmp equal ...\t");
if (strcmp(buffer, "eeeee") != 0) { if (strcmp(buffer, "eeeee") != 0) {
TC_PRINT ("failed\n"); TC_PRINT("failed\n");
return TC_FAIL; return TC_FAIL;
} else { } else {
TC_PRINT ("passed\n"); TC_PRINT("passed\n");
} }
TC_PRINT ("\tstrcmp greater ...\t"); TC_PRINT("\tstrcmp greater ...\t");
if (strcmp(buffer, "ddddd") <= 0) { if (strcmp(buffer, "ddddd") <= 0) {
TC_PRINT ("failed\n"); TC_PRINT("failed\n");
return TC_FAIL; return TC_FAIL;
} else { } else {
TC_PRINT ("passed\n"); TC_PRINT("passed\n");
} }
return TC_PASS; return TC_PASS;
@ -244,32 +244,32 @@ int strcmp_test (void)
* RETURNS: TC_PASS or TC_FAIL * RETURNS: TC_PASS or TC_FAIL
*/ */
int strncmp_test (void) int strncmp_test(void)
{ {
strncpy(buffer, "eeeeeeeeeeee", BUFSIZE); strncpy(buffer, "eeeeeeeeeeee", BUFSIZE);
TC_PRINT ("\tstrncmp 0 ...\t"); TC_PRINT("\tstrncmp 0 ...\t");
if (strncmp(buffer, "fffff", 0) != 0) { if (strncmp(buffer, "fffff", 0) != 0) {
TC_PRINT ("failed\n"); TC_PRINT("failed\n");
return TC_FAIL; return TC_FAIL;
} else { } else {
TC_PRINT ("passed\n"); TC_PRINT("passed\n");
} }
TC_PRINT ("\tstrncmp 3 ...\t"); TC_PRINT("\tstrncmp 3 ...\t");
if (strncmp(buffer, "eeeff", 3) != 0) { if (strncmp(buffer, "eeeff", 3) != 0) {
TC_PRINT ("failed\n"); TC_PRINT("failed\n");
return TC_FAIL; return TC_FAIL;
} else { } else {
TC_PRINT ("passed\n"); TC_PRINT("passed\n");
} }
TC_PRINT ("\tstrncmp 10 ...\t"); TC_PRINT("\tstrncmp 10 ...\t");
if (strncmp(buffer, "eeeeeeeeeeeff", BUFSIZE) != 0) { if (strncmp(buffer, "eeeeeeeeeeeff", BUFSIZE) != 0) {
TC_PRINT ("failed\n"); TC_PRINT("failed\n");
return TC_FAIL; return TC_FAIL;
} else { } else {
TC_PRINT ("passed\n"); TC_PRINT("passed\n");
} }
return TC_PASS; return TC_PASS;
@ -283,19 +283,19 @@ int strncmp_test (void)
* RETURNS: TC_PASS or TC_FAIL * RETURNS: TC_PASS or TC_FAIL
*/ */
int strcpy_test (void) int strcpy_test(void)
{ {
TC_PRINT ("\tstrcpy ...\t"); TC_PRINT("\tstrcpy ...\t");
memset (buffer, '\0', BUFSIZE); memset(buffer, '\0', BUFSIZE);
strcpy(buffer, "10 chars!!\0"); strcpy(buffer, "10 chars!!\0");
if (strcmp(buffer, "10 chars!!\0") != 0) { if (strcmp(buffer, "10 chars!!\0") != 0) {
TC_PRINT ("failed\n"); TC_PRINT("failed\n");
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT ("passed\n"); TC_PRINT("passed\n");
return TC_PASS; return TC_PASS;
} }
@ -306,20 +306,20 @@ int strcpy_test (void)
* RETURNS: TC_PASS or TC_FAIL * RETURNS: TC_PASS or TC_FAIL
*/ */
int strncpy_test (void) int strncpy_test(void)
{ {
TC_PRINT ("\tstrncpy ...\t"); TC_PRINT("\tstrncpy ...\t");
memset (buffer, '\0', BUFSIZE); memset(buffer, '\0', BUFSIZE);
strncpy(buffer, "This is over 10 characters", BUFSIZE); strncpy(buffer, "This is over 10 characters", BUFSIZE);
/* Purposely different values */ /* Purposely different values */
if (strncmp(buffer, "This is over 20 characters", BUFSIZE) != 0) { if (strncmp(buffer, "This is over 20 characters", BUFSIZE) != 0) {
TC_PRINT ("failed\n"); TC_PRINT("failed\n");
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT ("passed\n"); TC_PRINT("passed\n");
return TC_PASS; return TC_PASS;
} }
@ -330,27 +330,27 @@ int strncpy_test (void)
* RETURNS: TC_PASS or TC_FAIL * RETURNS: TC_PASS or TC_FAIL
*/ */
int strchr_test (void) int strchr_test(void)
{ {
char *rs = NULL; char *rs = NULL;
TC_PRINT ("\tstrchr ...\t"); TC_PRINT("\tstrchr ...\t");
memset (buffer, '\0', BUFSIZE); memset(buffer, '\0', BUFSIZE);
strncpy(buffer, "Copy 10", BUFSIZE); strncpy(buffer, "Copy 10", BUFSIZE);
rs = strchr(buffer, '1'); rs = strchr(buffer, '1');
if (!rs) { if (!rs) {
TC_PRINT ("failed\n"); TC_PRINT("failed\n");
return TC_FAIL; return TC_FAIL;
} }
if (strncmp(rs, "10", 2) != 0) { if (strncmp(rs, "10", 2) != 0) {
TC_PRINT ("failed\n"); TC_PRINT("failed\n");
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT ("passed\n"); TC_PRINT("passed\n");
return TC_PASS; return TC_PASS;
} }
@ -366,7 +366,7 @@ int stringTest(void)
TC_PRINT("Testing string.h library ...\n"); TC_PRINT("Testing string.h library ...\n");
if (memset_test() || strlen_test() || strcmp_test() || strcpy_test() || if (memset_test() || strlen_test() || strcmp_test() || strcpy_test() ||
strncpy_test() || strncmp_test() || strchr_test()) { strncpy_test() || strncmp_test() || strchr_test()) {
return TC_FAIL; return TC_FAIL;
} }
@ -388,8 +388,8 @@ int RegressionTask(void)
{ {
TC_PRINT("Validating access to supported libraries\n"); TC_PRINT("Validating access to supported libraries\n");
if (limitsTest () || stdboolTest () || stddefTest () || if (limitsTest() || stdboolTest() || stddefTest() ||
stdintTest () || stringTest ()) { stdintTest() || stringTest()) {
TC_PRINT("Library validation failed\n"); TC_PRINT("Library validation failed\n");
return TC_FAIL; return TC_FAIL;
} }

View file

@ -65,10 +65,10 @@ are not (yet) tested include:
/* defines */ /* defines */
#define MSGSIZE 16 /* Standard message data size */ #define MSGSIZE 16 /* Standard message data size */
#define XFER_PRIO 5 /* standard message transfer priority */ #define XFER_PRIO 5 /* standard message transfer priority */
#define MSG_INFO1 1234 /* Message info test value */ #define MSG_INFO1 1234 /* Message info test value */
#define MSG_INFO2 666 /* Message info test value */ #define MSG_INFO2 666 /* Message info test value */
/* locals */ /* locals */
@ -99,18 +99,18 @@ extern kmemory_pool_t smallBlkszPool;
* rx_task to receiverTask - destination for the message * rx_task to receiverTask - destination for the message
* mailbox to inMbox * mailbox to inMbox
* *
* @param inMsg The message being received.
* @param inMbox Mail box to receive the message.
* @param receiverTask Destination for the message.
* @param dataArea Pointer to (optional) buffer to send.
* @param dataSize Size of (optional) buffer to send.
* @param info Additional (optional) info to send.
*
* RETURNS: N/A * RETURNS: N/A
*/ */
static void setMsg_Sender static void setMsg_Sender(struct k_msg *inMsg, kmbox_t inMbox, ktask_t receiverTask,
( void *dataArea, uint32_t dataSize, uint32_t info)
struct k_msg *inMsg, /* the message being received */
kmbox_t inMbox, /* mail box to receive the message */
ktask_t receiverTask, /* destination for the message */
void *dataArea, /* pointer to (optional) buffer to send */
uint32_t dataSize, /* size of (optional) buffer to send */
uint32_t info /* additional (optional) info to send */
)
{ {
inMsg->rx_task = receiverTask; inMsg->rx_task = receiverTask;
inMsg->mailbox = inMbox; inMsg->mailbox = inMbox;
@ -129,17 +129,17 @@ static void setMsg_Sender
* tx_task to senderTask - receiver tries to get message from this source * tx_task to senderTask - receiver tries to get message from this source
* mailbox to inMbox * mailbox to inMbox
* *
* @param inMsg Message descriptor.
* @param inMbox Mail box to receive from.
* @param senderTask Sending task to receive from.
* @param inBuffer Incoming data area
* @param inBufferSize Size of incoming data area.
*
* RETURNS: N/A * RETURNS: N/A
*/ */
static void setMsg_Receiver static void setMsg_Receiver(struct k_msg *inMsg, kmbox_t inMbox, ktask_t senderTask,
( void *inBuffer, uint32_t inBufferSize)
struct k_msg *inMsg, /* message descriptor */
kmbox_t inMbox, /* mail box to receive from */
ktask_t senderTask, /* sending task to receive from */
void *inBuffer, /* incoming data area */
uint32_t inBufferSize /* size of incoming data area */
)
{ {
inMsg->mailbox = inMbox; inMsg->mailbox = inMbox;
inMsg->tx_task = senderTask; inMsg->tx_task = senderTask;
@ -154,15 +154,14 @@ static void setMsg_Receiver
* *
* setMsg_RecvBuf - sets rx_data field in msg and clears buffer * setMsg_RecvBuf - sets rx_data field in msg and clears buffer
* *
* @param inMsg The message being received.
* @param inBuffer Incoming data area.
* @param inBufferSize Size of incoming data area.
*
* RETURNS: N/A * RETURNS: N/A
*/ */
static void setMsg_RecvBuf static void setMsg_RecvBuf(struct k_msg *inMsg, char *inBuffer, uint32_t inBufferSize)
(
struct k_msg *inMsg, /* the message being received */
char *inBuffer, /* incoming data area */
uint32_t inBufferSize /* size of incoming data area */
)
{ {
inMsg->rx_data = inBuffer; inMsg->rx_data = inBuffer;
inMsg->size = inBufferSize; inMsg->size = inBufferSize;

View file

@ -66,15 +66,15 @@ static ksem_t resultSems[] = { SEM_TASKDONE, SEM_TASKFAIL, ENDLIST };
/* globals */ /* globals */
ktask_t msgSenderTask = MSGSENDERTASK; ktask_t msgSenderTask = MSGSENDERTASK;
ktask_t msgRcvrTask = MSGRCVRTASK; ktask_t msgRcvrTask = MSGRCVRTASK;
ksem_t semSync1 = SEM_SYNC1; ksem_t semSync1 = SEM_SYNC1;
ksem_t semSync2 = SEM_SYNC2; ksem_t semSync2 = SEM_SYNC2;
kmbox_t myMbox = MYMBOX; kmbox_t myMbox = MYMBOX;
kmbox_t noRcvrMbox = NORCVRMBOX; kmbox_t noRcvrMbox = NORCVRMBOX;
kmemory_pool_t testPool = TESTPOOL; kmemory_pool_t testPool = TESTPOOL;
kmemory_pool_t smallBlkszPool = SMALLBLKSZPOOL; kmemory_pool_t smallBlkszPool = SMALLBLKSZPOOL;
/******************************************************************************* /*******************************************************************************
@ -88,11 +88,11 @@ kmemory_pool_t smallBlkszPool = SMALLBLKSZPOOL;
*/ */
void MsgSenderTaskEntry(void) void MsgSenderTaskEntry(void)
{ {
extern int MsgSenderTask(void); extern int MsgSenderTask(void);
task_sem_give(resultSems[MsgSenderTask()]); task_sem_give(resultSems[MsgSenderTask()]);
} }
/******************************************************************************* /*******************************************************************************
* *
@ -105,11 +105,11 @@ void MsgSenderTaskEntry(void)
*/ */
void MsgRcvrTaskEntry(void) void MsgRcvrTaskEntry(void)
{ {
extern int MsgRcvrTask(void); extern int MsgRcvrTask(void);
task_sem_give(resultSems[MsgRcvrTask()]); task_sem_give(resultSems[MsgRcvrTask()]);
} }
/******************************************************************************* /*******************************************************************************
* *
@ -122,31 +122,31 @@ void MsgRcvrTaskEntry(void)
*/ */
void MonitorTaskEntry(void) void MonitorTaskEntry(void)
{ {
ksem_t result; ksem_t result;
int tasksDone; int tasksDone;
PRINT_DATA("Starting mailbox tests\n"); PRINT_DATA("Starting mailbox tests\n");
PRINT_LINE; PRINT_LINE;
/* /*
* the various test tasks start executing automatically; * the various test tasks start executing automatically;
* wait for all tasks to complete or a failure to occur, * wait for all tasks to complete or a failure to occur,
* then issue the appropriate test case summary message * then issue the appropriate test case summary message
*/ */
for (tasksDone = 0; tasksDone < NUM_TEST_TASKS; tasksDone++) { for (tasksDone = 0; tasksDone < NUM_TEST_TASKS; tasksDone++) {
result = task_sem_group_take_wait_timeout(resultSems, TIMEOUT); result = task_sem_group_take_wait_timeout(resultSems, TIMEOUT);
if (result != resultSems[TC_PASS]) { if (result != resultSems[TC_PASS]) {
if (result != resultSems[TC_FAIL]) { if (result != resultSems[TC_FAIL]) {
TC_ERROR("Monitor task timed out\n"); TC_ERROR("Monitor task timed out\n");
}
TC_END_RESULT(TC_FAIL);
TC_END_REPORT(TC_FAIL);
return;
} }
TC_END_RESULT(TC_FAIL);
TC_END_REPORT(TC_FAIL);
return;
}
} }
TC_END_RESULT(TC_PASS); TC_END_RESULT(TC_PASS);
TC_END_REPORT(TC_PASS); TC_END_REPORT(TC_PASS);
} }

View file

@ -89,19 +89,19 @@ static int tcRC = TC_PASS; /* test case return code */
*/ */
void Task10(void) void Task10(void)
{ {
int rv; int rv;
task_sleep(3 * ONE_SECOND + HALF_SECOND); task_sleep(3 * ONE_SECOND + HALF_SECOND);
/* Wait and boost owner priority to 10 */ /* Wait and boost owner priority to 10 */
rv = task_mutex_lock_wait_timeout(Mutex4, ONE_SECOND); rv = task_mutex_lock_wait_timeout(Mutex4, ONE_SECOND);
if (rv != RC_TIME) { if (rv != RC_TIME) {
tcRC = TC_FAIL; tcRC = TC_FAIL;
TC_ERROR("Failed to timeout on mutex 0x%x\n", Mutex4); TC_ERROR("Failed to timeout on mutex 0x%x\n", Mutex4);
return; return;
} }
} /* Task10 */ } /* Task10 */
/******************************************************************************* /*******************************************************************************
@ -112,29 +112,29 @@ void Task10(void)
*/ */
void Task15(void) void Task15(void)
{ {
int rv; int rv;
task_sleep(3 * ONE_SECOND + 3 * FOURTH_SECOND); task_sleep(3 * ONE_SECOND + 3 * FOURTH_SECOND);
/* /*
* Wait for the mutex. There is a higher priority level task waiting * Wait for the mutex. There is a higher priority level task waiting
* on the mutex, so request will not immediately contribute to raising * on the mutex, so request will not immediately contribute to raising
* the priority of the owning task (RegressionTask). When Task10 times out * the priority of the owning task (RegressionTask). When Task10 times out
* this task will become the highest priority waiting task. The priority * this task will become the highest priority waiting task. The priority
* of the owning task (RegressionTask) will not drop back to 20, but will * of the owning task (RegressionTask) will not drop back to 20, but will
* instead drop to 15. * instead drop to 15.
*/ */
rv = task_mutex_lock_wait_timeout(Mutex4, 2 * ONE_SECOND); rv = task_mutex_lock_wait_timeout(Mutex4, 2 * ONE_SECOND);
if (rv != RC_OK) { if (rv != RC_OK) {
tcRC = TC_FAIL; tcRC = TC_FAIL;
TC_ERROR("Failed to take mutex 0x%x\n", Mutex4); TC_ERROR("Failed to take mutex 0x%x\n", Mutex4);
return; return;
} }
task_mutex_unlock(Mutex4); task_mutex_unlock(Mutex4);
} }
/******************************************************************************* /*******************************************************************************
* *
@ -144,27 +144,27 @@ void Task15(void)
*/ */
void Task20(void) void Task20(void)
{ {
int rv; int rv;
task_sleep(2 * ONE_SECOND + HALF_SECOND); task_sleep(2 * ONE_SECOND + HALF_SECOND);
/* /*
* Wait and boost owner priority to 20. While waiting, another task of * Wait and boost owner priority to 20. While waiting, another task of
* a very low priority level will also wait for the mutex. Task20 is * a very low priority level will also wait for the mutex. Task20 is
* expected to time out around the 5.5 second mark. When it times out, * expected to time out around the 5.5 second mark. When it times out,
* Task45 will become the only waiting task for this mutex and the * Task45 will become the only waiting task for this mutex and the
* priority of the owning task RegressionTask will drop to 25. * priority of the owning task RegressionTask will drop to 25.
*/ */
rv = task_mutex_lock_wait_timeout(Mutex3, 3 * ONE_SECOND); rv = task_mutex_lock_wait_timeout(Mutex3, 3 * ONE_SECOND);
if (rv != RC_TIME) { if (rv != RC_TIME) {
tcRC = TC_FAIL; tcRC = TC_FAIL;
TC_ERROR("Failed to timeout on mutex 0x%x\n", Mutex3); TC_ERROR("Failed to timeout on mutex 0x%x\n", Mutex3);
return; return;
} }
} /* Task20 */ } /* Task20 */
/******************************************************************************* /*******************************************************************************
* *
@ -174,7 +174,7 @@ void Task20(void)
*/ */
void Task25(void) void Task25(void)
{ {
int rv; int rv;
task_sleep(ONE_SECOND + HALF_SECOND); task_sleep(ONE_SECOND + HALF_SECOND);
@ -184,10 +184,10 @@ void Task25(void)
tcRC = TC_FAIL; tcRC = TC_FAIL;
TC_ERROR("Failed to take mutex 0x%x\n", Mutex2); TC_ERROR("Failed to take mutex 0x%x\n", Mutex2);
return; return;
} }
task_mutex_unlock(Mutex2); task_mutex_unlock(Mutex2);
} /* Task25 */ } /* Task25 */
/******************************************************************************* /*******************************************************************************
* *
@ -197,7 +197,7 @@ void Task25(void)
*/ */
void Task30(void) void Task30(void)
{ {
int rv; int rv;
task_sleep(HALF_SECOND); /* Allow lower priority task to run */ task_sleep(HALF_SECOND); /* Allow lower priority task to run */
@ -208,17 +208,17 @@ void Task30(void)
tcRC = TC_FAIL; tcRC = TC_FAIL;
TC_ERROR("Failed to NOT take locked mutex 0x%x\n", Mutex1); TC_ERROR("Failed to NOT take locked mutex 0x%x\n", Mutex1);
return; return;
} }
rv = task_mutex_lock_wait(Mutex1); /* Wait and boost owner priority to 30 */ rv = task_mutex_lock_wait(Mutex1); /* Wait and boost owner priority to 30 */
if (rv != RC_OK) { if (rv != RC_OK) {
tcRC = TC_FAIL; tcRC = TC_FAIL;
TC_ERROR("Failed to take mutex 0x%x\n", Mutex1); TC_ERROR("Failed to take mutex 0x%x\n", Mutex1);
return; return;
} }
task_mutex_unlock(Mutex1); task_mutex_unlock(Mutex1);
} }
/******************************************************************************* /*******************************************************************************
* *
@ -228,7 +228,7 @@ void Task30(void)
*/ */
void Task45(void) void Task45(void)
{ {
int rv; int rv;
task_sleep(3 * ONE_SECOND + HALF_SECOND); task_sleep(3 * ONE_SECOND + HALF_SECOND);
@ -237,9 +237,9 @@ void Task45(void)
tcRC = TC_FAIL; tcRC = TC_FAIL;
TC_ERROR("Failed to take mutex 0x%x\n", Mutex2); TC_ERROR("Failed to take mutex 0x%x\n", Mutex2);
return; return;
}
task_mutex_unlock(Mutex3);
} }
task_mutex_unlock(Mutex3);
}
/******************************************************************************* /*******************************************************************************
* *
@ -251,7 +251,7 @@ void Task45(void)
*/ */
void RegressionTask(void) void RegressionTask(void)
{ {
int rv; int rv;
int i; int i;
kmutex_t mutexes[4] = {Mutex1, Mutex2, Mutex3, Mutex4}; kmutex_t mutexes[4] = {Mutex1, Mutex2, Mutex3, Mutex4};
@ -263,41 +263,41 @@ void RegressionTask(void)
PRINT_LINE; PRINT_LINE;
/* /*
* 1st iteration: Take Mutex1; Task30 waits on Mutex1 * 1st iteration: Take Mutex1; Task30 waits on Mutex1
* 2nd iteration: Take Mutex2: Task25 waits on Mutex2 * 2nd iteration: Take Mutex2: Task25 waits on Mutex2
* 3rd iteration: Take Mutex3; Task20 waits on Mutex3 * 3rd iteration: Take Mutex3; Task20 waits on Mutex3
* 4th iteration: Take Mutex4; Task10 waits on Mutex4 * 4th iteration: Take Mutex4; Task10 waits on Mutex4
*/ */
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
rv = task_mutex_lock(mutexes[i]); rv = task_mutex_lock(mutexes[i]);
if (rv != RC_OK) { if (rv != RC_OK) {
TC_ERROR("Failed to lock mutex 0x%x\n", mutexes[i]); TC_ERROR("Failed to lock mutex 0x%x\n", mutexes[i]);
tcRC = TC_FAIL; tcRC = TC_FAIL;
goto errorReturn; goto errorReturn;
} }
task_sleep(ONE_SECOND); task_sleep(ONE_SECOND);
rv = task_priority_get(); rv = task_priority_get();
if (rv != priority[i]) { if (rv != priority[i]) {
TC_ERROR("Expected priority %d, not %d\n", priority[i], rv); TC_ERROR("Expected priority %d, not %d\n", priority[i], rv);
tcRC = TC_FAIL; tcRC = TC_FAIL;
goto errorReturn; goto errorReturn;
}
if (tcRC != TC_PASS) { /* Catch any errors from other tasks */
goto errorReturn;
}
} }
/* ~ 4 seconds have passed */ if (tcRC != TC_PASS) { /* Catch any errors from other tasks */
goto errorReturn;
}
}
/* ~ 4 seconds have passed */
TC_PRINT("Done LOCKING! Current priority = %d\n", task_priority_get()); TC_PRINT("Done LOCKING! Current priority = %d\n", task_priority_get());
task_sleep(ONE_SECOND); /* Task10 should time out */ task_sleep(ONE_SECOND); /* Task10 should time out */
/* ~ 5 seconds have passed */ /* ~ 5 seconds have passed */
rv = task_priority_get(); rv = task_priority_get();
if (rv != 15) { if (rv != 15) {
@ -305,7 +305,7 @@ void RegressionTask(void)
TC_ERROR("Expected priority %d, not %d\n", 15, rv); TC_ERROR("Expected priority %d, not %d\n", 15, rv);
tcRC = TC_FAIL; tcRC = TC_FAIL;
goto errorReturn; goto errorReturn;
} }
task_mutex_unlock(Mutex4); task_mutex_unlock(Mutex4);
rv = task_priority_get(); rv = task_priority_get();
@ -314,40 +314,40 @@ void RegressionTask(void)
TC_ERROR("Expected priority %d, not %d\n", 20, rv); TC_ERROR("Expected priority %d, not %d\n", 20, rv);
tcRC = TC_FAIL; tcRC = TC_FAIL;
goto errorReturn; goto errorReturn;
} }
task_sleep(ONE_SECOND); /* Task20 should time out */ task_sleep(ONE_SECOND); /* Task20 should time out */
/* ~ 6 seconds have passed */ /* ~ 6 seconds have passed */
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
rv = task_priority_get(); rv = task_priority_get();
if (rv != dropPri[i]) { if (rv != dropPri[i]) {
TC_ERROR("Expected priority %d, not %d\n", dropPri[i], rv); TC_ERROR("Expected priority %d, not %d\n", dropPri[i], rv);
tcRC = TC_FAIL; tcRC = TC_FAIL;
goto errorReturn; goto errorReturn;
} }
task_mutex_unlock(giveMutex[i]); task_mutex_unlock(giveMutex[i]);
if (tcRC != TC_PASS) { if (tcRC != TC_PASS) {
goto errorReturn; goto errorReturn;
}
} }
}
rv = task_priority_get(); rv = task_priority_get();
if (rv != 40) { if (rv != 40) {
TC_ERROR("Expected priority %d, not %d\n", 40, rv); TC_ERROR("Expected priority %d, not %d\n", 40, rv);
tcRC = TC_FAIL; tcRC = TC_FAIL;
goto errorReturn; goto errorReturn;
} }
task_sleep(ONE_SECOND); /* Give Task45 time to run */ task_sleep(ONE_SECOND); /* Give Task45 time to run */
if (tcRC != TC_PASS) { if (tcRC != TC_PASS) {
goto errorReturn; goto errorReturn;
} }
errorReturn: errorReturn:
TC_END_RESULT(tcRC); TC_END_RESULT(tcRC);
TC_END_REPORT(tcRC); TC_END_REPORT(tcRC);
} /* RegressionTask */ } /* RegressionTask */

View file

@ -82,11 +82,11 @@ kpipe_t pipeId = PIPE_ID;
*/ */
void RegressionTaskEntry(void) void RegressionTaskEntry(void)
{ {
extern int RegressionTask(void); extern int RegressionTask(void);
task_sem_give(resultSems[RegressionTask()]); task_sem_give(resultSems[RegressionTask()]);
} }
/******************************************************************************* /*******************************************************************************
* *
@ -99,11 +99,11 @@ void RegressionTaskEntry(void)
*/ */
void AlternateTaskEntry(void) void AlternateTaskEntry(void)
{ {
extern int AlternateTask(void); extern int AlternateTask(void);
task_sem_give(resultSems[AlternateTask()]); task_sem_give(resultSems[AlternateTask()]);
} }
/******************************************************************************* /*******************************************************************************
* *
@ -116,31 +116,31 @@ void AlternateTaskEntry(void)
*/ */
void MonitorTaskEntry(void) void MonitorTaskEntry(void)
{ {
ksem_t result; ksem_t result;
int tasksDone; int tasksDone;
PRINT_DATA("Starting pipe tests\n"); PRINT_DATA("Starting pipe tests\n");
PRINT_LINE; PRINT_LINE;
/* /*
* the various test tasks start executing automatically; * the various test tasks start executing automatically;
* wait for all tasks to complete or a failure to occur, * wait for all tasks to complete or a failure to occur,
* then issue the appropriate test case summary message * then issue the appropriate test case summary message
*/ */
for (tasksDone = 0; tasksDone < NUM_TEST_TASKS; tasksDone++) { for (tasksDone = 0; tasksDone < NUM_TEST_TASKS; tasksDone++) {
result = task_sem_group_take_wait_timeout(resultSems, TIMEOUT); result = task_sem_group_take_wait_timeout(resultSems, TIMEOUT);
if (result != resultSems[TC_PASS]) { if (result != resultSems[TC_PASS]) {
if (result != resultSems[TC_FAIL]) { if (result != resultSems[TC_FAIL]) {
TC_ERROR("Monitor task timed out\n"); TC_ERROR("Monitor task timed out\n");
}
TC_END_RESULT(TC_FAIL);
TC_END_REPORT(TC_FAIL);
return;
} }
TC_END_RESULT(TC_FAIL);
TC_END_REPORT(TC_FAIL);
return;
}
} }
TC_END_RESULT(TC_PASS); TC_END_RESULT(TC_PASS);
TC_END_REPORT(TC_PASS); TC_END_REPORT(TC_PASS);
} }

View file

@ -64,7 +64,7 @@ typedef struct {
K_PIPE_OPTION options; /* options for task_pipe_XXX() APIs */ K_PIPE_OPTION options; /* options for task_pipe_XXX() APIs */
int sent; /* expected # of bytes sent */ int sent; /* expected # of bytes sent */
int rcode; /* expected return code */ int rcode; /* expected return code */
} SIZE_EXPECT; } SIZE_EXPECT;
/* locals */ /* locals */
@ -180,7 +180,7 @@ void microObjectsInit(void)
for (i = 0; i < sizeof(rxBuffer); i++) { for (i = 0; i < sizeof(rxBuffer); i++) {
txBuffer[i] = (char) i; txBuffer[i] = (char) i;
} }
} }
/******************************************************************************* /*******************************************************************************
@ -199,9 +199,9 @@ int receiveBufferCheck(char *buffer, int size)
for (j = 0; j < size; j++) { for (j = 0; j < size; j++) {
if (buffer[j] != (char) j) { if (buffer[j] != (char) j) {
return j; return j;
}
} }
}
return size; return size;
} }
@ -230,76 +230,76 @@ int pipePutHelperWork(SIZE_EXPECT *singleItems, int nSingles,
for (i = 0; i < nSingles; i++) { for (i = 0; i < nSingles; i++) {
(void)task_sem_take_wait(altSem); (void)task_sem_take_wait(altSem);
for (j = 0; j < sizeof(rxBuffer); j++) { for (j = 0; j < sizeof(rxBuffer); j++) {
rxBuffer[j] = 0; rxBuffer[j] = 0;
} }
rv = task_pipe_get(pipeId, rxBuffer, singleItems[i].size, rv = task_pipe_get(pipeId, rxBuffer, singleItems[i].size,
&bytesReceived, singleItems[i].options); &bytesReceived, singleItems[i].options);
if (rv != singleItems[i].rcode) { if (rv != singleItems[i].rcode) {
TC_ERROR("task_pipe_get(%d bytes) : Expected %d not %d.\n" TC_ERROR("task_pipe_get(%d bytes) : Expected %d not %d.\n"
" bytesReceived = %d\n", " bytesReceived = %d\n",
singleItems[i].size, singleItems[i].rcode, singleItems[i].size, singleItems[i].rcode,
rv, bytesReceived); rv, bytesReceived);
return TC_FAIL; return TC_FAIL;
} }
if (bytesReceived != singleItems[i].sent) { if (bytesReceived != singleItems[i].sent) {
TC_ERROR("task_pipe_get(%d) : " TC_ERROR("task_pipe_get(%d) : "
"Expected %d bytes to be received, not %d\n", "Expected %d bytes to be received, not %d\n",
singleItems[i].size, singleItems[i].sent, bytesReceived); singleItems[i].size, singleItems[i].sent, bytesReceived);
return TC_FAIL; return TC_FAIL;
} }
index = receiveBufferCheck(rxBuffer, bytesReceived); index = receiveBufferCheck(rxBuffer, bytesReceived);
if (index != bytesReceived) { if (index != bytesReceived) {
TC_ERROR("pipePutHelper: rxBuffer[%d] is %d, not %d\n", TC_ERROR("pipePutHelper: rxBuffer[%d] is %d, not %d\n",
index, rxBuffer[index], index); index, rxBuffer[index], index);
return TC_FAIL; return TC_FAIL;
} }
task_sem_give(counterSem); task_sem_give(counterSem);
task_sem_give(regSem); task_sem_give(regSem);
} }
/* /*
* Get items from the pipe. There should be more than one item * Get items from the pipe. There should be more than one item
* stored in it. * stored in it.
*/ */
(void)task_sem_take_wait(altSem); (void)task_sem_take_wait(altSem);
for (i = 0; i < nMany; i++) { for (i = 0; i < nMany; i++) {
for (j = 0; j < sizeof(rxBuffer); j++) { for (j = 0; j < sizeof(rxBuffer); j++) {
rxBuffer[j] = 0; rxBuffer[j] = 0;
} }
rv = task_pipe_get(pipeId, rxBuffer, manyItems[i].size, rv = task_pipe_get(pipeId, rxBuffer, manyItems[i].size,
&bytesReceived, manyItems[i].options); &bytesReceived, manyItems[i].options);
if (rv != manyItems[i].rcode) { if (rv != manyItems[i].rcode) {
TC_ERROR("task_pipe_get(%d bytes) : Expected %d not %d.\n" TC_ERROR("task_pipe_get(%d bytes) : Expected %d not %d.\n"
" bytesReceived = %d, iteration: %d\n", " bytesReceived = %d, iteration: %d\n",
manyItems[i].size, manyItems[i].rcode, manyItems[i].size, manyItems[i].rcode,
rv, bytesReceived, i+1); rv, bytesReceived, i+1);
return TC_FAIL; return TC_FAIL;
} }
if (bytesReceived != manyItems[i].sent) { if (bytesReceived != manyItems[i].sent) {
TC_ERROR("task_pipe_get(%d) : " TC_ERROR("task_pipe_get(%d) : "
"Expected %d bytes to be received, not %d\n", "Expected %d bytes to be received, not %d\n",
manyItems[i].size, manyItems[i].sent, bytesReceived); manyItems[i].size, manyItems[i].sent, bytesReceived);
return TC_FAIL; return TC_FAIL;
} }
index = receiveBufferCheck(rxBuffer, bytesReceived); index = receiveBufferCheck(rxBuffer, bytesReceived);
if (index != bytesReceived) { if (index != bytesReceived) {
TC_ERROR("pipeGetHelper: rxBuffer[%d] is %d, not %d\n", TC_ERROR("pipeGetHelper: rxBuffer[%d] is %d, not %d\n",
index, rxBuffer[index], index); index, rxBuffer[index], index);
return TC_FAIL; return TC_FAIL;
} }
task_sem_give(counterSem); task_sem_give(counterSem);
} }
task_sem_give(regSem); /* Wake the RegressionTask */ task_sem_give(regSem); /* Wake the RegressionTask */
@ -318,25 +318,25 @@ int pipePutHelper(void)
int rv; /* return value from pipePutHelperWork() */ int rv; /* return value from pipePutHelperWork() */
rv = pipePutHelperWork(all_N, ARRAY_SIZE(all_N), rv = pipePutHelperWork(all_N, ARRAY_SIZE(all_N),
many_all_N, ARRAY_SIZE(many_all_N)); many_all_N, ARRAY_SIZE(many_all_N));
if (rv != TC_PASS) { if (rv != TC_PASS) {
TC_ERROR("Failed on all_N/many_all_N test\n"); TC_ERROR("Failed on all_N/many_all_N test\n");
return TC_FAIL; return TC_FAIL;
} }
rv = pipePutHelperWork(one_to_N, ARRAY_SIZE(one_to_N), rv = pipePutHelperWork(one_to_N, ARRAY_SIZE(one_to_N),
many_one_to_N, ARRAY_SIZE(many_one_to_N)); many_one_to_N, ARRAY_SIZE(many_one_to_N));
if (rv != TC_PASS) { if (rv != TC_PASS) {
TC_ERROR("Failed on _1_TO_N/many_1_TO_N test\n"); TC_ERROR("Failed on _1_TO_N/many_1_TO_N test\n");
return TC_FAIL; return TC_FAIL;
} }
rv = pipePutHelperWork(zero_to_N, ARRAY_SIZE(zero_to_N), rv = pipePutHelperWork(zero_to_N, ARRAY_SIZE(zero_to_N),
many_zero_to_N, ARRAY_SIZE(many_zero_to_N)); many_zero_to_N, ARRAY_SIZE(many_zero_to_N));
if (rv != TC_PASS) { if (rv != TC_PASS) {
TC_ERROR("Failed on _0_TO_N/many_0_TO_N test\n"); TC_ERROR("Failed on _0_TO_N/many_0_TO_N test\n");
return TC_FAIL; return TC_FAIL;
} }
return TC_PASS; return TC_PASS;
} }
@ -367,65 +367,65 @@ int pipePutTestWork(SIZE_EXPECT *singleItems, int nSingles,
for (i = 0; i < nSingles; i++) { for (i = 0; i < nSingles; i++) {
rv = task_pipe_put(pipeId, txBuffer, singleItems[i].size, rv = task_pipe_put(pipeId, txBuffer, singleItems[i].size,
&bytesWritten, singleItems[i].options); &bytesWritten, singleItems[i].options);
if (rv != singleItems[i].rcode) { if (rv != singleItems[i].rcode) {
TC_ERROR("task_pipe_put(%d) : Expected %d not %d.\n" TC_ERROR("task_pipe_put(%d) : Expected %d not %d.\n"
" bytesWritten = %d, Iteration: %d\n", " bytesWritten = %d, Iteration: %d\n",
singleItems[i].size, singleItems[i].rcode, singleItems[i].size, singleItems[i].rcode,
rv, bytesWritten, i + 1); rv, bytesWritten, i + 1);
return TC_FAIL; return TC_FAIL;
} }
if (bytesWritten != singleItems[i].sent) { if (bytesWritten != singleItems[i].sent) {
TC_ERROR("task_pipe_put(%d) : " TC_ERROR("task_pipe_put(%d) : "
"Expected %d bytes to be written, not %d\n", "Expected %d bytes to be written, not %d\n",
singleItems[i].size, singleItems[i].sent, bytesWritten); singleItems[i].size, singleItems[i].sent, bytesWritten);
return TC_FAIL; return TC_FAIL;
} }
task_sem_give(altSem); task_sem_give(altSem);
(void)task_sem_take_wait(regSem); (void)task_sem_take_wait(regSem);
nitem = task_sem_count_get(counterSem) - 1; nitem = task_sem_count_get(counterSem) - 1;
if (nitem != i) { if (nitem != i) {
TC_ERROR("Expected item number is %d, not %d\n", TC_ERROR("Expected item number is %d, not %d\n",
i, nitem); i, nitem);
return TC_FAIL; return TC_FAIL;
}
} }
}
/* This time, more than one item will be in the pipe at a time */ /* This time, more than one item will be in the pipe at a time */
task_sem_reset(counterSem); task_sem_reset(counterSem);
for (i = 0; i < nMany; i++) { for (i = 0; i < nMany; i++) {
rv = task_pipe_put(pipeId, txBuffer, manyItems[i].size, rv = task_pipe_put(pipeId, txBuffer, manyItems[i].size,
&bytesWritten, manyItems[i].options); &bytesWritten, manyItems[i].options);
if (rv != manyItems[i].rcode) { if (rv != manyItems[i].rcode) {
TC_ERROR("task_pipe_put(%d) : Expected %d not %d.\n" TC_ERROR("task_pipe_put(%d) : Expected %d not %d.\n"
" bytesWritten = %d, iteration: %d\n", " bytesWritten = %d, iteration: %d\n",
manyItems[i].size, manyItems[i].rcode, manyItems[i].size, manyItems[i].rcode,
rv, bytesWritten, i + 1); rv, bytesWritten, i + 1);
return TC_FAIL; return TC_FAIL;
}
if (bytesWritten != manyItems[i].sent) {
TC_ERROR("task_pipe_put(%d) : "
"Expected %d bytes to be written, not %d\n",
manyItems[i].size, manyItems[i].sent, bytesWritten);
return TC_FAIL;
}
} }
if (bytesWritten != manyItems[i].sent) {
TC_ERROR("task_pipe_put(%d) : "
"Expected %d bytes to be written, not %d\n",
manyItems[i].size, manyItems[i].sent, bytesWritten);
return TC_FAIL;
}
}
task_sem_give(altSem); /* Wake the alternate task */ task_sem_give(altSem); /* Wake the alternate task */
/* wait for other task reading all the items from pipe */ /* wait for other task reading all the items from pipe */
(void)task_sem_take_wait(regSem); (void)task_sem_take_wait(regSem);
if (task_sem_count_get(counterSem) != nMany) { if (task_sem_count_get(counterSem) != nMany) {
TC_ERROR("Expected number of items %d, not %d\n", TC_ERROR("Expected number of items %d, not %d\n",
nMany, task_sem_count_get(counterSem)); nMany, task_sem_count_get(counterSem));
return TC_FAIL; return TC_FAIL;
} }
return TC_PASS; return TC_PASS;
} }
@ -444,25 +444,25 @@ int pipePutTest(void)
int rv; /* return value from pipePutTestWork() */ int rv; /* return value from pipePutTestWork() */
rv = pipePutTestWork(all_N, ARRAY_SIZE(all_N), rv = pipePutTestWork(all_N, ARRAY_SIZE(all_N),
many_all_N, ARRAY_SIZE(many_all_N)); many_all_N, ARRAY_SIZE(many_all_N));
if (rv != TC_PASS) { if (rv != TC_PASS) {
TC_ERROR("Failed on _ALL_N/many_ALL_N test\n"); TC_ERROR("Failed on _ALL_N/many_ALL_N test\n");
return TC_FAIL; return TC_FAIL;
} }
rv = pipePutTestWork(one_to_N, ARRAY_SIZE(one_to_N), rv = pipePutTestWork(one_to_N, ARRAY_SIZE(one_to_N),
many_one_to_N, ARRAY_SIZE(many_one_to_N)); many_one_to_N, ARRAY_SIZE(many_one_to_N));
if (rv != TC_PASS) { if (rv != TC_PASS) {
TC_ERROR("Failed on _1_TO_N/many_1_TO_N test\n"); TC_ERROR("Failed on _1_TO_N/many_1_TO_N test\n");
return TC_FAIL; return TC_FAIL;
} }
rv = pipePutTestWork(zero_to_N, ARRAY_SIZE(zero_to_N), rv = pipePutTestWork(zero_to_N, ARRAY_SIZE(zero_to_N),
many_zero_to_N, ARRAY_SIZE(many_zero_to_N)); many_zero_to_N, ARRAY_SIZE(many_zero_to_N));
if (rv != TC_PASS) { if (rv != TC_PASS) {
TC_ERROR("Failed on _0_TO_N/many_0_TO_N test\n"); TC_ERROR("Failed on _0_TO_N/many_0_TO_N test\n");
return TC_FAIL; return TC_FAIL;
} }
return TC_PASS; return TC_PASS;
} }
@ -482,49 +482,49 @@ int pipePutWaitHelper(void)
(void)task_sem_take_wait(altSem); /* Wait until test is ready */ (void)task_sem_take_wait(altSem); /* Wait until test is ready */
/* 1. task_pipe_get_wait() will force a context switch to RegressionTask() */ /* 1. task_pipe_get_wait() will force a context switch to RegressionTask() */
rv = task_pipe_get_wait(pipeId, rxBuffer, PIPE_SIZE, rv = task_pipe_get_wait(pipeId, rxBuffer, PIPE_SIZE,
&bytesRead, _ALL_N); &bytesRead, _ALL_N);
if ((rv != RC_OK) || (bytesRead != PIPE_SIZE)) { if ((rv != RC_OK) || (bytesRead != PIPE_SIZE)) {
TC_ERROR("Expected return code %d, not %d\n" TC_ERROR("Expected return code %d, not %d\n"
"Expected %d bytes to be read, not %d\n", "Expected %d bytes to be read, not %d\n",
RC_OK, rv, PIPE_SIZE, bytesRead); RC_OK, rv, PIPE_SIZE, bytesRead);
return TC_FAIL; return TC_FAIL;
} }
/* 2. task_pipe_get_wait() will force a context switch to RegressionTask(). */ /* 2. task_pipe_get_wait() will force a context switch to RegressionTask(). */
rv = task_pipe_get_wait(pipeId, rxBuffer, PIPE_SIZE, rv = task_pipe_get_wait(pipeId, rxBuffer, PIPE_SIZE,
&bytesRead, _1_TO_N); &bytesRead, _1_TO_N);
if ((rv != RC_OK) || (bytesRead != PIPE_SIZE)) { if ((rv != RC_OK) || (bytesRead != PIPE_SIZE)) {
TC_ERROR("Expected return code %d, not %d\n" TC_ERROR("Expected return code %d, not %d\n"
"Expected %d bytes to be read, not %d\n", "Expected %d bytes to be read, not %d\n",
RC_OK, rv, PIPE_SIZE, bytesRead); RC_OK, rv, PIPE_SIZE, bytesRead);
return TC_FAIL; return TC_FAIL;
} }
/* /*
* Before emptying the pipe, check that task_pipe_get_wait() fails when * Before emptying the pipe, check that task_pipe_get_wait() fails when
* using the _0_TO_N option. * using the _0_TO_N option.
*/ */
rv = task_pipe_get_wait(pipeId, rxBuffer, PIPE_SIZE / 2, rv = task_pipe_get_wait(pipeId, rxBuffer, PIPE_SIZE / 2,
&bytesRead, _0_TO_N); &bytesRead, _0_TO_N);
if (rv != RC_FAIL) { if (rv != RC_FAIL) {
TC_ERROR("Expected return code %d, not %d\n", RC_FAIL, rv); TC_ERROR("Expected return code %d, not %d\n", RC_FAIL, rv);
return TC_FAIL; return TC_FAIL;
} }
/* 3. Empty the pipe in two reads */ /* 3. Empty the pipe in two reads */
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
rv = task_pipe_get(pipeId, rxBuffer, PIPE_SIZE / 2, rv = task_pipe_get(pipeId, rxBuffer, PIPE_SIZE / 2,
&bytesRead, _0_TO_N); &bytesRead, _0_TO_N);
if ((rv != RC_OK) || (bytesRead != PIPE_SIZE / 2)) { if ((rv != RC_OK) || (bytesRead != PIPE_SIZE / 2)) {
TC_ERROR("Expected return code %d, not %d\n" TC_ERROR("Expected return code %d, not %d\n"
"Expected %d bytes to be read, not %d\n", "Expected %d bytes to be read, not %d\n",
RC_OK, rv, PIPE_SIZE / 2, bytesRead); RC_OK, rv, PIPE_SIZE / 2, bytesRead);
return TC_FAIL; return TC_FAIL;
}
} }
}
task_sem_give(regSem); task_sem_give(regSem);
@ -543,49 +543,49 @@ int pipePutWaitTest(void)
int rv; /* return code from task_pipe_put_wait() */ int rv; /* return code from task_pipe_put_wait() */
int bytesWritten; /* # of bytes written to pipe */ int bytesWritten; /* # of bytes written to pipe */
/* 1. Fill the pipe */ /* 1. Fill the pipe */
rv = task_pipe_put_wait(pipeId, txBuffer, PIPE_SIZE, rv = task_pipe_put_wait(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _ALL_N); &bytesWritten, _ALL_N);
if ((rv != RC_OK) || (bytesWritten != PIPE_SIZE)) { if ((rv != RC_OK) || (bytesWritten != PIPE_SIZE)) {
TC_ERROR("Return code: expected %d, got %d\n" TC_ERROR("Return code: expected %d, got %d\n"
"Bytes written: expected %d, got %d\n", "Bytes written: expected %d, got %d\n",
RC_OK, rv, PIPE_SIZE, bytesWritten); RC_OK, rv, PIPE_SIZE, bytesWritten);
return TC_FAIL; return TC_FAIL;
} }
task_sem_give(altSem); /* Wake the alternate task */ task_sem_give(altSem); /* Wake the alternate task */
/* 2. task_pipe_put_wait() will force a context switch to AlternateTask(). */ /* 2. task_pipe_put_wait() will force a context switch to AlternateTask(). */
rv = task_pipe_put_wait(pipeId, txBuffer, PIPE_SIZE, rv = task_pipe_put_wait(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _ALL_N); &bytesWritten, _ALL_N);
if ((rv != RC_OK) || (bytesWritten != PIPE_SIZE)) { if ((rv != RC_OK) || (bytesWritten != PIPE_SIZE)) {
TC_ERROR("Return code: expected %d, got %d\n" TC_ERROR("Return code: expected %d, got %d\n"
"Bytes written: expected %d, got %d\n", "Bytes written: expected %d, got %d\n",
RC_OK, rv, PIPE_SIZE, bytesWritten); RC_OK, rv, PIPE_SIZE, bytesWritten);
return TC_FAIL; return TC_FAIL;
} }
/* 3. task_pipe_put_wait() will force a context switch to AlternateTask(). */ /* 3. task_pipe_put_wait() will force a context switch to AlternateTask(). */
rv = task_pipe_put_wait(pipeId, txBuffer, PIPE_SIZE, rv = task_pipe_put_wait(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _1_TO_N); &bytesWritten, _1_TO_N);
if ((rv != RC_OK) || (bytesWritten != PIPE_SIZE)) { if ((rv != RC_OK) || (bytesWritten != PIPE_SIZE)) {
TC_ERROR("Return code: expected %d, got %d\n" TC_ERROR("Return code: expected %d, got %d\n"
"Bytes written: expected %d, got %d\n", "Bytes written: expected %d, got %d\n",
RC_OK, rv, PIPE_SIZE, bytesWritten); RC_OK, rv, PIPE_SIZE, bytesWritten);
return TC_FAIL; return TC_FAIL;
} }
/* This should return immediately as _0_TO_N with a wait is an error. */ /* This should return immediately as _0_TO_N with a wait is an error. */
rv = task_pipe_put_wait(pipeId, txBuffer, PIPE_SIZE, rv = task_pipe_put_wait(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _0_TO_N); &bytesWritten, _0_TO_N);
if ((rv != RC_FAIL) || (bytesWritten != 0)) { if ((rv != RC_FAIL) || (bytesWritten != 0)) {
TC_ERROR("Return code: expected %d, got %d\n" TC_ERROR("Return code: expected %d, got %d\n"
"Bytes written: expected %d, got %d\n", "Bytes written: expected %d, got %d\n",
RC_FAIL, rv, 0, bytesWritten); RC_FAIL, rv, 0, bytesWritten);
return TC_FAIL; return TC_FAIL;
} }
/* Wait for AlternateTask()'s pipePutWaitHelper() to finish */ /* Wait for AlternateTask()'s pipePutWaitHelper() to finish */
(void)task_sem_take_wait(regSem); (void)task_sem_take_wait(regSem);
return TC_PASS; return TC_PASS;
@ -606,49 +606,49 @@ int pipePutTimeoutHelper(void)
(void)task_sem_take_wait(altSem); /* Wait until test is ready */ (void)task_sem_take_wait(altSem); /* Wait until test is ready */
/* 1. task_pipe_get_wait_timeout() will force a context switch to RegressionTask() */ /* 1. task_pipe_get_wait_timeout() will force a context switch to RegressionTask() */
rv = task_pipe_get_wait_timeout(pipeId, rxBuffer, PIPE_SIZE, rv = task_pipe_get_wait_timeout(pipeId, rxBuffer, PIPE_SIZE,
&bytesRead, _ALL_N, ONE_SECOND); &bytesRead, _ALL_N, ONE_SECOND);
if ((rv != RC_OK) || (bytesRead != PIPE_SIZE)) { if ((rv != RC_OK) || (bytesRead != PIPE_SIZE)) {
TC_ERROR("Expected return code %d, not %d\n" TC_ERROR("Expected return code %d, not %d\n"
"Expected %d bytes to be read, not %d\n", "Expected %d bytes to be read, not %d\n",
RC_OK, rv, PIPE_SIZE, bytesRead); RC_OK, rv, PIPE_SIZE, bytesRead);
return TC_FAIL; return TC_FAIL;
} }
/* 2. task_pipe_get_wait_timeout() will force a context switch to RegressionTask(). */ /* 2. task_pipe_get_wait_timeout() will force a context switch to RegressionTask(). */
rv = task_pipe_get_wait_timeout(pipeId, rxBuffer, PIPE_SIZE, rv = task_pipe_get_wait_timeout(pipeId, rxBuffer, PIPE_SIZE,
&bytesRead, _1_TO_N, ONE_SECOND); &bytesRead, _1_TO_N, ONE_SECOND);
if ((rv != RC_OK) || (bytesRead != PIPE_SIZE)) { if ((rv != RC_OK) || (bytesRead != PIPE_SIZE)) {
TC_ERROR("Expected return code %d, not %d\n" TC_ERROR("Expected return code %d, not %d\n"
"Expected %d bytes to be read, not %d\n", "Expected %d bytes to be read, not %d\n",
RC_OK, rv, PIPE_SIZE, bytesRead); RC_OK, rv, PIPE_SIZE, bytesRead);
return TC_FAIL; return TC_FAIL;
} }
/* /*
* Before emptying the pipe, check that task_pipe_get_wait_timeout() fails when * Before emptying the pipe, check that task_pipe_get_wait_timeout() fails when
* using the _0_TO_N option. * using the _0_TO_N option.
*/ */
rv = task_pipe_get_wait_timeout(pipeId, rxBuffer, PIPE_SIZE / 2, rv = task_pipe_get_wait_timeout(pipeId, rxBuffer, PIPE_SIZE / 2,
&bytesRead, _0_TO_N, ONE_SECOND); &bytesRead, _0_TO_N, ONE_SECOND);
if (rv != RC_FAIL) { if (rv != RC_FAIL) {
TC_ERROR("Expected return code %d, not %d\n", RC_FAIL, rv); TC_ERROR("Expected return code %d, not %d\n", RC_FAIL, rv);
return TC_FAIL; return TC_FAIL;
} }
/* 3. Empty the pipe in two reads */ /* 3. Empty the pipe in two reads */
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
rv = task_pipe_get(pipeId, rxBuffer, PIPE_SIZE / 2, rv = task_pipe_get(pipeId, rxBuffer, PIPE_SIZE / 2,
&bytesRead, _0_TO_N); &bytesRead, _0_TO_N);
if ((rv != RC_OK) || (bytesRead != PIPE_SIZE / 2)) { if ((rv != RC_OK) || (bytesRead != PIPE_SIZE / 2)) {
TC_ERROR("Expected return code %d, not %d\n" TC_ERROR("Expected return code %d, not %d\n"
"Expected %d bytes to be read, not %d\n", "Expected %d bytes to be read, not %d\n",
RC_OK, rv, PIPE_SIZE / 2, bytesRead); RC_OK, rv, PIPE_SIZE / 2, bytesRead);
return TC_FAIL; return TC_FAIL;
}
} }
}
task_sem_give(regSem); task_sem_give(regSem);
@ -667,67 +667,69 @@ int pipePutTimeoutTest(void)
int rv; /* return code from task_pipe_put_wait_timeout() */ int rv; /* return code from task_pipe_put_wait_timeout() */
int bytesWritten; /* # of bytes written to task_pipe_put_wait_timeout() */ int bytesWritten; /* # of bytes written to task_pipe_put_wait_timeout() */
/* 1. Fill the pipe */ /* 1. Fill the pipe */
rv = task_pipe_put_wait_timeout(pipeId, txBuffer, PIPE_SIZE, rv = task_pipe_put_wait_timeout(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _ALL_N, ONE_SECOND); &bytesWritten, _ALL_N, ONE_SECOND);
if ((rv != RC_OK) || (bytesWritten != PIPE_SIZE)) { if ((rv != RC_OK) || (bytesWritten != PIPE_SIZE)) {
TC_ERROR("Return code: expected %d, got %d\n" TC_ERROR("Return code: expected %d, got %d\n"
"Bytes written: expected %d, got %d\n", "Bytes written: expected %d, got %d\n",
RC_OK, rv, PIPE_SIZE, bytesWritten); RC_OK, rv, PIPE_SIZE, bytesWritten);
return TC_FAIL; return TC_FAIL;
} }
/* Timeout while waiting to put data into the pipe */ /* Timeout while waiting to put data into the pipe */
rv = task_pipe_put_wait_timeout(pipeId, txBuffer, PIPE_SIZE, rv = task_pipe_put_wait_timeout(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _ALL_N, ONE_SECOND); &bytesWritten, _ALL_N, ONE_SECOND);
if ((rv != RC_TIME) || (bytesWritten != 0)) { if ((rv != RC_TIME) || (bytesWritten != 0)) {
TC_ERROR("Return code: expected %d, got %d\n" TC_ERROR("Return code: expected %d, got %d\n"
"Bytes written: expected %d, got %d\n", "Bytes written: expected %d, got %d\n",
RC_TIME, rv, 0, bytesWritten); RC_TIME, rv, 0, bytesWritten);
return TC_FAIL; return TC_FAIL;
} }
rv = task_pipe_put_wait_timeout(pipeId, txBuffer, PIPE_SIZE, rv = task_pipe_put_wait_timeout(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _1_TO_N, ONE_SECOND); &bytesWritten, _1_TO_N, ONE_SECOND);
if ((rv != RC_TIME) || (bytesWritten != 0)) { if ((rv != RC_TIME) || (bytesWritten != 0)) {
TC_ERROR("Return code: expected %d, got %d\n" TC_ERROR("Return code: expected %d, got %d\n"
"Bytes written: expected %d, got %d\n", "Bytes written: expected %d, got %d\n",
RC_TIME, rv, 0, bytesWritten); RC_TIME, rv, 0, bytesWritten);
return TC_FAIL; return TC_FAIL;
} }
task_sem_give(altSem); /* Wake the alternate task */ task_sem_give(altSem); /* Wake the alternate task */
/* 2. task_pipe_put_wait() will force a context switch to AlternateTask(). */ /* 2. task_pipe_put_wait() will force a context switch to AlternateTask(). */
rv = task_pipe_put_wait_timeout(pipeId, txBuffer, PIPE_SIZE, rv = task_pipe_put_wait_timeout(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _ALL_N, ONE_SECOND); &bytesWritten, _ALL_N, ONE_SECOND);
if ((rv != RC_OK) || (bytesWritten != PIPE_SIZE)) { if ((rv != RC_OK) || (bytesWritten != PIPE_SIZE)) {
TC_ERROR("Return code: expected %d, got %d\n" TC_ERROR("Return code: expected %d, got %d\n"
"Bytes written: expected %d, got %d\n", "Bytes written: expected %d, got %d\n",
RC_OK, rv, PIPE_SIZE, bytesWritten); return TC_FAIL; } RC_OK, rv, PIPE_SIZE, bytesWritten);
/* 3. task_pipe_put_wait() will force a context switch to AlternateTask(). */
rv = task_pipe_put_wait_timeout(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _1_TO_N, ONE_SECOND);
if ((rv != RC_OK) || (bytesWritten != PIPE_SIZE)) {
TC_ERROR("Return code: expected %d, got %d\n"
"Bytes written: expected %d, got %d\n",
RC_OK, rv, PIPE_SIZE, bytesWritten);
return TC_FAIL; return TC_FAIL;
} }
/* This should return immediately as _0_TO_N with a wait is an error. */ /* 3. task_pipe_put_wait() will force a context switch to AlternateTask(). */
rv = task_pipe_put_wait_timeout(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _1_TO_N, ONE_SECOND);
if ((rv != RC_OK) || (bytesWritten != PIPE_SIZE)) {
TC_ERROR("Return code: expected %d, got %d\n"
"Bytes written: expected %d, got %d\n",
RC_OK, rv, PIPE_SIZE, bytesWritten);
return TC_FAIL;
}
/* This should return immediately as _0_TO_N with a wait is an error. */
rv = task_pipe_put_wait(pipeId, txBuffer, PIPE_SIZE, rv = task_pipe_put_wait(pipeId, txBuffer, PIPE_SIZE,
&bytesWritten, _0_TO_N); &bytesWritten, _0_TO_N);
if ((rv != RC_FAIL) || (bytesWritten != 0)) { if ((rv != RC_FAIL) || (bytesWritten != 0)) {
TC_ERROR("Return code: expected %d, got %d\n" TC_ERROR("Return code: expected %d, got %d\n"
"Bytes written: expected %d, got %d\n", "Bytes written: expected %d, got %d\n",
RC_FAIL, rv, 0, bytesWritten); RC_FAIL, rv, 0, bytesWritten);
return TC_FAIL; return TC_FAIL;
} }
/* Wait for AlternateTask()'s pipePutWaitHelper() to finish */ /* Wait for AlternateTask()'s pipePutWaitHelper() to finish */
(void)task_sem_take_wait(regSem); (void)task_sem_take_wait(regSem);
return TC_PASS; return TC_PASS;
@ -756,28 +758,28 @@ int pipeGetTest(void)
for (j = 0; j < ARRAY_SIZE(options); j++) { for (j = 0; j < ARRAY_SIZE(options); j++) {
for (i = 0; i < ARRAY_SIZE(size); i++) { for (i = 0; i < ARRAY_SIZE(size); i++) {
rv = task_pipe_get(pipeId, rxBuffer, size[i], rv = task_pipe_get(pipeId, rxBuffer, size[i],
&bytesRead, options[j]); &bytesRead, options[j]);
if (rv != RC_FAIL) { if (rv != RC_FAIL) {
TC_ERROR("Expected return code %d, not %d\n", RC_FAIL, rv); TC_ERROR("Expected return code %d, not %d\n", RC_FAIL, rv);
return TC_FAIL; return TC_FAIL;
} }
}
} }
}
for (i = 0; i < ARRAY_SIZE(size); i++) { for (i = 0; i < ARRAY_SIZE(size); i++) {
rv = task_pipe_get(pipeId, rxBuffer, size[i], rv = task_pipe_get(pipeId, rxBuffer, size[i],
&bytesRead, _0_TO_N); &bytesRead, _0_TO_N);
if (rv != RC_OK) { if (rv != RC_OK) {
TC_ERROR("Expected return code %d, not %d\n", RC_OK, rv); TC_ERROR("Expected return code %d, not %d\n", RC_OK, rv);
return TC_FAIL; return TC_FAIL;
} }
if (bytesRead != 0) { if (bytesRead != 0) {
TC_ERROR("Expected <bytesRead> %d, not %d\n", 0, bytesRead); TC_ERROR("Expected <bytesRead> %d, not %d\n", 0, bytesRead);
return TC_FAIL; return TC_FAIL;
}
} }
}
return TC_PASS; return TC_PASS;
} }
@ -799,22 +801,22 @@ int pipeGetWaitHelperWork(SIZE_EXPECT *items, int nItems)
int bytesSent; /* # of bytes sent to task_pipe_put_wait() */ int bytesSent; /* # of bytes sent to task_pipe_put_wait() */
for (i = 0; i < nItems; i++) { for (i = 0; i < nItems; i++) {
/* /*
* Pipe should be empty. Most calls to task_pipe_get_wait() should * Pipe should be empty. Most calls to task_pipe_get_wait() should
* block until the call to task_pipe_put() is performed in the routine * block until the call to task_pipe_put() is performed in the routine
* pipeGetWaitHelperWork(). * pipeGetWaitHelperWork().
*/ */
bytesSent = 0; bytesSent = 0;
rv = task_pipe_put_wait(pipeId, rxBuffer, items[i].size, rv = task_pipe_put_wait(pipeId, rxBuffer, items[i].size,
&bytesSent, items[i].options); &bytesSent, items[i].options);
if ((rv != items[i].rcode) || (bytesSent != items[i].sent)) { if ((rv != items[i].rcode) || (bytesSent != items[i].sent)) {
TC_ERROR("Expected return value %d, got %d\n" TC_ERROR("Expected return value %d, got %d\n"
"Expected bytesSent = %d, got %d\n", "Expected bytesSent = %d, got %d\n",
items[i].rcode, rv, 0, bytesSent); items[i].rcode, rv, 0, bytesSent);
return TC_FAIL; return TC_FAIL;
}
} }
}
return TC_PASS; return TC_PASS;
} }
@ -836,13 +838,13 @@ int pipeGetWaitHelper(void)
if (rv != TC_PASS) { if (rv != TC_PASS) {
TC_ERROR("Failed on _ALL_N test\n"); TC_ERROR("Failed on _ALL_N test\n");
return TC_FAIL; return TC_FAIL;
} }
rv = pipeGetWaitHelperWork(wait_one_to_N, ARRAY_SIZE(wait_one_to_N)); rv = pipeGetWaitHelperWork(wait_one_to_N, ARRAY_SIZE(wait_one_to_N));
if (rv != TC_PASS) { if (rv != TC_PASS) {
TC_ERROR("Failed on _1_TO_N test\n"); TC_ERROR("Failed on _1_TO_N test\n");
return TC_FAIL; return TC_FAIL;
} }
return TC_PASS; return TC_PASS;
} }
@ -864,21 +866,21 @@ int pipeGetWaitTestWork(SIZE_EXPECT *items, int nItems)
int bytesRead; /* # of bytes read from task_pipe_get_wait() */ int bytesRead; /* # of bytes read from task_pipe_get_wait() */
for (i = 0; i < nItems; i++) { for (i = 0; i < nItems; i++) {
/* /*
* Pipe should be empty. Most calls to task_pipe_get_wait() should * Pipe should be empty. Most calls to task_pipe_get_wait() should
* block until the call to task_pipe_put() is performed in the routine * block until the call to task_pipe_put() is performed in the routine
* pipeGetWaitHelperWork(). * pipeGetWaitHelperWork().
*/ */
rv = task_pipe_get_wait(pipeId, rxBuffer, items[i].size, rv = task_pipe_get_wait(pipeId, rxBuffer, items[i].size,
&bytesRead, items[i].options); &bytesRead, items[i].options);
if ((rv != items[i].rcode) || (bytesRead != items[i].sent)) { if ((rv != items[i].rcode) || (bytesRead != items[i].sent)) {
TC_ERROR("Expected return value %d, got %d\n" TC_ERROR("Expected return value %d, got %d\n"
"Expected bytesRead = %d, got %d\n", "Expected bytesRead = %d, got %d\n",
items[i].rcode, rv, 0, bytesRead); items[i].rcode, rv, 0, bytesRead);
return TC_FAIL; return TC_FAIL;
}
} }
}
return TC_PASS; return TC_PASS;
} }
@ -901,20 +903,20 @@ int pipeGetWaitTest(void)
if (rv != TC_PASS) { if (rv != TC_PASS) {
TC_ERROR("Failed on _ALL_N test\n"); TC_ERROR("Failed on _ALL_N test\n");
return TC_FAIL; return TC_FAIL;
} }
rv = pipeGetWaitTestWork(wait_one_to_N, ARRAY_SIZE(wait_one_to_N)); rv = pipeGetWaitTestWork(wait_one_to_N, ARRAY_SIZE(wait_one_to_N));
if (rv != TC_PASS) { if (rv != TC_PASS) {
TC_ERROR("Failed on _1_TO_N test\n"); TC_ERROR("Failed on _1_TO_N test\n");
return TC_FAIL; return TC_FAIL;
} }
rv = task_pipe_get_wait(pipeId, rxBuffer, PIPE_SIZE, rv = task_pipe_get_wait(pipeId, rxBuffer, PIPE_SIZE,
&bytesRead, _0_TO_N); &bytesRead, _0_TO_N);
if (rv != RC_FAIL) { if (rv != RC_FAIL) {
TC_ERROR("Expected return code of %d, not %d\n", RC_FAIL, rv); TC_ERROR("Expected return code of %d, not %d\n", RC_FAIL, rv);
return TC_FAIL; return TC_FAIL;
} }
return TC_PASS; return TC_PASS;
} }
@ -934,17 +936,17 @@ int pipeGetTimeoutTest(void)
for (i = 0; i < ARRAY_SIZE(timeout_cases); i++) { for (i = 0; i < ARRAY_SIZE(timeout_cases); i++) {
rv = task_pipe_get_wait_timeout(pipeId, rxBuffer, timeout_cases[i].size, rv = task_pipe_get_wait_timeout(pipeId, rxBuffer, timeout_cases[i].size,
&bytesRead, timeout_cases[i].options, ONE_SECOND); &bytesRead, timeout_cases[i].options, ONE_SECOND);
if ((rv != timeout_cases[i].rcode) || if ((rv != timeout_cases[i].rcode) ||
(bytesRead != timeout_cases[i].sent)) { (bytesRead != timeout_cases[i].sent)) {
TC_ERROR("Expected return code %d, got %d\n" TC_ERROR("Expected return code %d, got %d\n"
"Expected <bytesRead> %d, got %d\n" "Expected <bytesRead> %d, got %d\n"
"Iteration %d\n", "Iteration %d\n",
timeout_cases[i].rcode, rv, timeout_cases[i].sent, timeout_cases[i].rcode, rv, timeout_cases[i].sent,
bytesRead, i + 1); bytesRead, i + 1);
return TC_FAIL; return TC_FAIL;
}
} }
}
return TC_PASS; return TC_PASS;
} }
@ -965,33 +967,33 @@ int AlternateTask(void)
rv = pipePutHelper(); rv = pipePutHelper();
if (rv != TC_PASS) { if (rv != TC_PASS) {
return TC_FAIL; return TC_FAIL;
} }
rv = pipePutWaitHelper(); rv = pipePutWaitHelper();
if (rv != TC_PASS) { if (rv != TC_PASS) {
return TC_FAIL; return TC_FAIL;
} }
rv = pipePutTimeoutHelper(); rv = pipePutTimeoutHelper();
if (rv != TC_PASS) { if (rv != TC_PASS) {
return TC_FAIL; return TC_FAIL;
} }
/* /*
* There is no pipeGetHelper() as the task_pipe_get() checks have * There is no pipeGetHelper() as the task_pipe_get() checks have
* either been done in pipePutHelper(), or pipeGetTest(). * either been done in pipePutHelper(), or pipeGetTest().
*/ */
rv = pipeGetWaitHelper(); rv = pipeGetWaitHelper();
if (rv != TC_PASS) { if (rv != TC_PASS) {
return TC_FAIL; return TC_FAIL;
} }
/* /*
* There is no pipeGetTimeoutHelper() as the task_pipe_get_wait_timeout() checks * There is no pipeGetTimeoutHelper() as the task_pipe_get_wait_timeout() checks
* have either been done in pipePutTimeoutHelper() or * have either been done in pipePutTimeoutHelper() or
* pipeGetTimeoutTest(). * pipeGetTimeoutTest().
*/ */
return TC_PASS; return TC_PASS;
} }
@ -1014,38 +1016,38 @@ int RegressionTask(void)
TC_PRINT("Testing task_pipe_put() ...\n"); TC_PRINT("Testing task_pipe_put() ...\n");
tcRC = pipePutTest(); tcRC = pipePutTest();
if (tcRC != TC_PASS) { if (tcRC != TC_PASS) {
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT("Testing task_pipe_put_wait() ...\n"); TC_PRINT("Testing task_pipe_put_wait() ...\n");
tcRC = pipePutWaitTest(); tcRC = pipePutWaitTest();
if (tcRC != TC_PASS) { if (tcRC != TC_PASS) {
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT("Testing task_pipe_put_wait_timeout() ...\n"); TC_PRINT("Testing task_pipe_put_wait_timeout() ...\n");
tcRC = pipePutTimeoutTest(); tcRC = pipePutTimeoutTest();
if (tcRC != TC_PASS) { if (tcRC != TC_PASS) {
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT("Testing task_pipe_get() ...\n"); TC_PRINT("Testing task_pipe_get() ...\n");
tcRC = pipeGetTest(); tcRC = pipeGetTest();
if (tcRC != TC_PASS) { if (tcRC != TC_PASS) {
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT("Testing task_pipe_get_wait() ...\n"); TC_PRINT("Testing task_pipe_get_wait() ...\n");
tcRC = pipeGetWaitTest(); tcRC = pipeGetWaitTest();
if (tcRC != TC_PASS) { if (tcRC != TC_PASS) {
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT("Testing task_pipe_get_wait_timeout() ...\n"); TC_PRINT("Testing task_pipe_get_wait_timeout() ...\n");
tcRC = pipeGetTimeoutTest(); tcRC = pipeGetTimeoutTest();
if (tcRC != TC_PASS) { if (tcRC != TC_PASS) {
return TC_FAIL; return TC_FAIL;
} }
return TC_PASS; return TC_PASS;
} }

View file

@ -59,7 +59,7 @@ This modules tests the following memory pool routines:
typedef struct { typedef struct {
struct k_block *block; /* pointer to block data */ struct k_block *block; /* pointer to block data */
kmemory_pool_t poolId; /* pool ID */ kmemory_pool_t poolId; /* pool ID */
int size; /* request size in bytes */ int size; /* request size in bytes */
int32_t timeout; /* # of ticks to wait */ int32_t timeout; /* # of ticks to wait */
int rcode; /* expected return code */ int rcode; /* expected return code */

View file

@ -58,43 +58,46 @@ This modules tests the following secure routines:
*/ */
void MainTask(void) void MainTask(void)
{ {
int result; int result;
/* wait for the first task to start */ /* wait for the first task to start */
result = task_sem_take_wait_timeout(SEMA1, WAIT_TOUT); result = task_sem_take_wait_timeout(SEMA1, WAIT_TOUT);
if (result != RC_OK) { if (result != RC_OK) {
TC_ERROR("Test task 1 did not start properly\n"); TC_ERROR("Test task 1 did not start properly\n");
goto fail; goto fail;
}
/* now we check the first task to perform the test and die */
result = task_sem_take_wait_timeout(SEMA1, WAIT_TOUT);
if (result == RC_TIME) {
TC_PRINT("As expected, test task 1 did not continue operating \n");
TC_PRINT("after calling memcpy_s with incorrect parameters\n");
}
else {
TC_ERROR("Test task 1 unexpectedly continued\n"
"after calling memcpy_s with incorrect parameters\n");
goto fail;
} }
/* wait for the second task to start */ /* now we check the first task to perform the test and die */
result = task_sem_take_wait_timeout(SEMA2, WAIT_TOUT); result = task_sem_take_wait_timeout(SEMA1, WAIT_TOUT);
if (result != RC_OK) {
TC_ERROR("Test task 2 did not start properly\n");
goto fail;
}
/* now we check the second task to perform the test and die */
result = task_sem_take_wait_timeout(SEMA2, WAIT_TOUT);
if (result == RC_TIME) { if (result == RC_TIME) {
TC_PRINT("As expected, test task 2 did not continue operating \n"); TC_PRINT("As expected, test task 1 did not continue operating \n");
TC_PRINT("after calling strcpy_s with incorrect parameters\n"); TC_PRINT("after calling memcpy_s with incorrect parameters\n");
} }
else { else {
TC_ERROR("Test task 2 unexpectedly continued\n" TC_ERROR("Test task 1 unexpectedly continued\n"
"after calling memcpy_s with incorrect parameters\n"); "after calling memcpy_s with incorrect parameters\n");
goto fail; goto fail;
} }
/* wait for the second task to start */
result = task_sem_take_wait_timeout(SEMA2, WAIT_TOUT);
if (result != RC_OK) {
TC_ERROR("Test task 2 did not start properly\n");
goto fail;
}
/* now we check the second task to perform the test and die */
result = task_sem_take_wait_timeout(SEMA2, WAIT_TOUT);
if (result == RC_TIME) {
TC_PRINT("As expected, test task 2 did not continue operating \n");
TC_PRINT("after calling strcpy_s with incorrect parameters\n");
}
else {
TC_ERROR("Test task 2 unexpectedly continued\n"
"after calling memcpy_s with incorrect parameters\n");
goto fail;
}
TC_END_RESULT(TC_PASS); TC_END_RESULT(TC_PASS);
TC_END_REPORT(TC_PASS); TC_END_REPORT(TC_PASS);
return; return;
@ -102,7 +105,7 @@ void MainTask(void)
fail: fail:
TC_END_RESULT(TC_FAIL); TC_END_RESULT(TC_FAIL);
TC_END_REPORT(TC_FAIL); TC_END_REPORT(TC_FAIL);
} }
/******************************************************************************* /*******************************************************************************
* *
@ -113,18 +116,19 @@ fail:
* RETURNS: N/A * RETURNS: N/A
*/ */
void MemcpyTask(void) void MemcpyTask(void)
{ {
uint8_t buf1[BUFSIZE]; uint8_t buf1[BUFSIZE];
uint8_t buf2[BUFSIZE + 1]; uint8_t buf2[BUFSIZE + 1];
/* do correct memory copy */ /* do correct memory copy */
k_memcpy_s(buf2, sizeof(buf2), buf1, sizeof(buf1)); k_memcpy_s(buf2, sizeof(buf2), buf1, sizeof(buf1));
task_sem_give(SEMA1); task_sem_give(SEMA1);
task_yield(); task_yield();
/* do incorrect memory copy */
/* do incorrect memory copy */
k_memcpy_s(buf1, sizeof(buf1), buf2, sizeof(buf2)); k_memcpy_s(buf1, sizeof(buf1), buf2, sizeof(buf2));
task_sem_give(SEMA1); task_sem_give(SEMA1);
} }
/******************************************************************************* /*******************************************************************************
* *
@ -135,22 +139,22 @@ void MemcpyTask(void)
* RETURNS: N/A * RETURNS: N/A
*/ */
void StrcpyTask(void) void StrcpyTask(void)
{ {
char buf1[BUFSIZE]; char buf1[BUFSIZE];
char buf2[BUFSIZE] = { '1', '2', '3', '4', '5', char buf2[BUFSIZE] = { '1', '2', '3', '4', '5', '6', '7', '8', '9', 0 };
'6', '7', '8', '9', 0 };
/* do correct string copy */ /* do correct string copy */
strcpy_s(buf1, sizeof(buf1), buf2); strcpy_s(buf1, sizeof(buf1), buf2);
task_sem_give(SEMA2); task_sem_give(SEMA2);
task_yield(); task_yield();
/* /*
* Make the string not \0 terminated as a result * Make the string not \0 terminated as a result
* strcpy_s has to make an error * strcpy_s has to make an error
*/ */
buf2[BUFSIZE - 1] = '0'; buf2[BUFSIZE - 1] = '0';
/* do incorrect string copy */
/* do incorrect string copy */
strcpy_s(buf1, sizeof(buf1), buf2); strcpy_s(buf1, sizeof(buf1), buf2);
task_sem_give(SEMA2); task_sem_give(SEMA2);
} }

View file

@ -249,22 +249,22 @@ void MonitorTaskEntry(void)
PRINT_DATA("Starting semaphore tests\n"); PRINT_DATA("Starting semaphore tests\n");
PRINT_LINE; PRINT_LINE;
/* /*
* the various test tasks start executing automatically; * the various test tasks start executing automatically;
* wait for all tasks to complete or a failure to occur, * wait for all tasks to complete or a failure to occur,
* then issue the appropriate test case summary message * then issue the appropriate test case summary message
*/ */
for (tasksDone = 0; tasksDone < NUM_TEST_TASKS; tasksDone++) { for (tasksDone = 0; tasksDone < NUM_TEST_TASKS; tasksDone++) {
result = task_sem_group_take_wait_timeout(resultSems, SECONDS(60)); result = task_sem_group_take_wait_timeout(resultSems, SECONDS(60));
if (result != resultSems[TC_PASS]) { if (result != resultSems[TC_PASS]) {
if (result != resultSems[TC_FAIL]) { if (result != resultSems[TC_FAIL]) {
TC_ERROR("Monitor task timed out\n"); TC_ERROR("Monitor task timed out\n");
}
TC_END_RESULT(TC_FAIL);
TC_END_REPORT(TC_FAIL);
return;
} }
TC_END_RESULT(TC_FAIL);
TC_END_REPORT(TC_FAIL);
return;
}
} }
TC_END_RESULT(TC_PASS); TC_END_RESULT(TC_PASS);

View file

@ -81,15 +81,15 @@ extern ksem_t semList[];
*/ */
int simpleSemaTest(void) int simpleSemaTest(void)
{ {
int signalCount; int signalCount;
int i; int i;
int status; int status;
/* /*
* Signal the semaphore several times from an ISR. After each signal, * Signal the semaphore several times from an ISR. After each signal,
* check the signal count. * check the signal count.
*/ */
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
trigger_isrSemaSignal(simpleSem); trigger_isrSemaSignal(simpleSem);
@ -97,74 +97,74 @@ int simpleSemaTest(void)
task_sleep(10); /* Time for low priority task to run. */ task_sleep(10); /* Time for low priority task to run. */
signalCount = task_sem_count_get(simpleSem); signalCount = task_sem_count_get(simpleSem);
if (signalCount != (i + 1)) { if (signalCount != (i + 1)) {
TC_ERROR("<signalCount> error. Expected %d, got %d\n", TC_ERROR("<signalCount> error. Expected %d, got %d\n",
i + 1, signalCount); i + 1, signalCount);
return TC_FAIL; return TC_FAIL;
}
} }
}
/* /*
* Signal the semaphore several times from a task. After each signal, * Signal the semaphore several times from a task. After each signal,
* check the signal count. * check the signal count.
*/ */
for (i = 5; i < 10; i++) { for (i = 5; i < 10; i++) {
task_sem_give(simpleSem); task_sem_give(simpleSem);
signalCount = task_sem_count_get(simpleSem); signalCount = task_sem_count_get(simpleSem);
if (signalCount != (i + 1)) { if (signalCount != (i + 1)) {
TC_ERROR("<signalCount> error. Expected %d, got %d\n", TC_ERROR("<signalCount> error. Expected %d, got %d\n",
i + 1, signalCount); i + 1, signalCount);
return TC_FAIL; return TC_FAIL;
}
} }
}
/* /*
* Test the semaphore without wait. Check the signal count after each * Test the semaphore without wait. Check the signal count after each
* attempt (it should be decrementing by 1 each time). * attempt (it should be decrementing by 1 each time).
*/ */
for (i = 9; i >= 4; i--) { for (i = 9; i >= 4; i--) {
status = task_sem_take(simpleSem); status = task_sem_take(simpleSem);
if (status != RC_OK) { if (status != RC_OK) {
TC_ERROR("task_sem_take(SIMPLE_SEM) error. Expected %d, not %d.\n", TC_ERROR("task_sem_take(SIMPLE_SEM) error. Expected %d, not %d.\n",
RC_OK, status); RC_OK, status);
return TC_FAIL; return TC_FAIL;
} }
signalCount = task_sem_count_get(simpleSem); signalCount = task_sem_count_get(simpleSem);
if (signalCount != i) { if (signalCount != i) {
TC_ERROR("<signalCount> error. Expected %d, not %d\n", TC_ERROR("<signalCount> error. Expected %d, not %d\n",
i, signalCount); i, signalCount);
return TC_FAIL; return TC_FAIL;
}
} }
}
task_sem_reset(simpleSem); task_sem_reset(simpleSem);
/* /*
* The semaphore's signal count should now be zero (0). Test the * The semaphore's signal count should now be zero (0). Test the
* semaphore without wait. It should fail. * semaphore without wait. It should fail.
*/ */
for (i = 0; i < 10; i++) { for (i = 0; i < 10; i++) {
status = task_sem_take(simpleSem); status = task_sem_take(simpleSem);
if (status != RC_FAIL) { if (status != RC_FAIL) {
TC_ERROR("task_sem_take(SIMPLE_SEM) error. Expected %d, got %d.\n", TC_ERROR("task_sem_take(SIMPLE_SEM) error. Expected %d, got %d.\n",
RC_FAIL, status); RC_FAIL, status);
return TC_FAIL; return TC_FAIL;
} }
signalCount = task_sem_count_get(simpleSem); signalCount = task_sem_count_get(simpleSem);
if (signalCount != 0) { if (signalCount != 0) {
TC_ERROR("<signalCount> error. Expected %d, not %d\n", TC_ERROR("<signalCount> error. Expected %d, not %d\n",
0, signalCount); 0, signalCount);
return TC_FAIL; return TC_FAIL;
}
} }
}
return TC_PASS; return TC_PASS;
} }
/******************************************************************************* /*******************************************************************************
* *
@ -174,55 +174,55 @@ int simpleSemaTest(void)
*/ */
int simpleSemaWaitTest(void) int simpleSemaWaitTest(void)
{ {
int status; int status;
int i; int i;
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
/* Wait one second for SIMPLE_SEM. Timeout is expected. */ /* Wait one second for SIMPLE_SEM. Timeout is expected. */
status = task_sem_take_wait_timeout(simpleSem, OBJ_TIMEOUT); status = task_sem_take_wait_timeout(simpleSem, OBJ_TIMEOUT);
if (status != RC_TIME) { if (status != RC_TIME) {
TC_ERROR("task_sem_take_wait_timeout() error. Expected %d, got %d\n", TC_ERROR("task_sem_take_wait_timeout() error. Expected %d, got %d\n",
RC_TIME, status); RC_TIME, status);
return TC_FAIL; return TC_FAIL;
}
} }
}
/* /*
* Signal the semaphore upon which the alternate task is waiting. The * Signal the semaphore upon which the alternate task is waiting. The
* alternate task (which is at a lower priority) will cause SIMPLE_SEM * alternate task (which is at a lower priority) will cause SIMPLE_SEM
* to be signalled, thus waking this task. * to be signalled, thus waking this task.
*/ */
task_sem_give(altSem); task_sem_give(altSem);
status = task_sem_take_wait_timeout(simpleSem, OBJ_TIMEOUT); status = task_sem_take_wait_timeout(simpleSem, OBJ_TIMEOUT);
if (status != RC_OK) { if (status != RC_OK) {
TC_ERROR("task_sem_take_wait_timeout() error. Expected %d, got %d\n", TC_ERROR("task_sem_take_wait_timeout() error. Expected %d, got %d\n",
RC_OK, status); RC_OK, status);
return TC_FAIL; return TC_FAIL;
} }
/* /*
* Note that task_sem_take_wait() has been tested when waking up the alternate * Note that task_sem_take_wait() has been tested when waking up the alternate
* task. Since previous tests had this task waiting, the alternate task * task. Since previous tests had this task waiting, the alternate task
* must have had the time to enter the state where it is waiting for the * must have had the time to enter the state where it is waiting for the
* ALTTASK_SEM semaphore to be given. Thus, we do not need to test for * ALTTASK_SEM semaphore to be given. Thus, we do not need to test for
* it here. * it here.
* *
* Now wait on SIMPLE_SEM again. This time it will be woken up by an * Now wait on SIMPLE_SEM again. This time it will be woken up by an
* ISR signalling the semaphore. * ISR signalling the semaphore.
*/ */
status = task_sem_take_wait_timeout(simpleSem, OBJ_TIMEOUT); status = task_sem_take_wait_timeout(simpleSem, OBJ_TIMEOUT);
if (status != RC_OK) { if (status != RC_OK) {
TC_ERROR("task_sem_take_wait_timeout() error. Expected %d, got %d\n", TC_ERROR("task_sem_take_wait_timeout() error. Expected %d, got %d\n",
RC_OK, status); RC_OK, status);
return TC_FAIL; return TC_FAIL;
} }
return TC_PASS; return TC_PASS;
} }
/******************************************************************************* /*******************************************************************************
* *
@ -232,77 +232,77 @@ int simpleSemaWaitTest(void)
*/ */
int simpleGroupTest(void) int simpleGroupTest(void)
{ {
int i; int i;
int j; int j;
int status; int status;
ksem_t value; ksem_t value;
/* Ensure that the semaphores in the group are reset */ /* Ensure that the semaphores in the group are reset */
task_sem_group_reset(semList); task_sem_group_reset(semList);
for (i = 0; semList[i] != ENDLIST; i++) { for (i = 0; semList[i] != ENDLIST; i++) {
status = task_sem_count_get(semList[i]); status = task_sem_count_get(semList[i]);
if (status != 0) { if (status != 0) {
TC_ERROR("task_sem_count_get() returned %d not %d\n", status, 0); TC_ERROR("task_sem_count_get() returned %d not %d\n", status, 0);
return TC_FAIL; return TC_FAIL;
}
} }
}
/* Timeout while waiting for a semaphore from the group */ /* Timeout while waiting for a semaphore from the group */
value = task_sem_group_take_wait_timeout(semList, OBJ_TIMEOUT); value = task_sem_group_take_wait_timeout(semList, OBJ_TIMEOUT);
if (value != ENDLIST) { if (value != ENDLIST) {
TC_ERROR("task_sem_group_take_wait_timeout() returned %d not %d\n", TC_ERROR("task_sem_group_take_wait_timeout() returned %d not %d\n",
value, ENDGROUP); value, ENDGROUP);
return TC_FAIL; return TC_FAIL;
} }
/* Signal the semaphores in the group */ /* Signal the semaphores in the group */
for (i = 0; i < 10; i++) { for (i = 0; i < 10; i++) {
task_sem_group_give(semList); task_sem_group_give(semList);
for (j = 0; semList[j] != ENDLIST; j++) { for (j = 0; semList[j] != ENDLIST; j++) {
status = task_sem_count_get(semList[j]); status = task_sem_count_get(semList[j]);
if (status != i + 1) { if (status != i + 1) {
TC_ERROR("task_sem_count_get() returned %d not %d\n", TC_ERROR("task_sem_count_get() returned %d not %d\n",
status, i + 1); status, i + 1);
return TC_FAIL; return TC_FAIL;
} }
}
} }
}
/* Get the semaphores */ /* Get the semaphores */
for (i = 9; i >= 5; i--) { for (i = 9; i >= 5; i--) {
value = task_sem_group_take_wait_timeout(semList, 0); value = task_sem_group_take_wait_timeout(semList, 0);
for (j = 0; semList[j] != ENDLIST; j++) { for (j = 0; semList[j] != ENDLIST; j++) {
status = task_sem_count_get(semList[j]); status = task_sem_count_get(semList[j]);
if (status != (value == semList[j] ? i : 10)) { if (status != (value == semList[j] ? i : 10)) {
TC_ERROR("task_sem_count_get(0x%x) returned %d not %d\n", TC_ERROR("task_sem_count_get(0x%x) returned %d not %d\n",
semList[j], status, (value == semList[j]) ? i : 10); semList[j], status, (value == semList[j]) ? i : 10);
return TC_FAIL; return TC_FAIL;
} }
}
} }
}
/* Reset the semaphores in the group */ /* Reset the semaphores in the group */
task_sem_group_reset(semList); task_sem_group_reset(semList);
for (i = 0; semList[i] != ENDLIST; i++) { for (i = 0; semList[i] != ENDLIST; i++) {
status = task_sem_count_get(semList[i]); status = task_sem_count_get(semList[i]);
if (status != 0) { if (status != 0) {
TC_ERROR("task_sem_count_get() returned %d not %d\n", status, 0); TC_ERROR("task_sem_count_get() returned %d not %d\n", status, 0);
return TC_FAIL; return TC_FAIL;
}
} }
}
return TC_PASS; return TC_PASS;
} }
/******************************************************************************* /*******************************************************************************
* *
@ -315,57 +315,57 @@ int simpleGroupTest(void)
*/ */
int simpleGroupWaitTest(void) int simpleGroupWaitTest(void)
{ {
int i; int i;
ksem_t sema; ksem_t sema;
task_sem_give(altSem); /* Wake the alternate task */ task_sem_give(altSem); /* Wake the alternate task */
/* /*
* Wait for a semaphore to be signalled by the alternate task. * Wait for a semaphore to be signalled by the alternate task.
* Each semaphore in the group will be tested. * Each semaphore in the group will be tested.
*/ */
for (i = 0; semList[i] != ENDLIST; i++) { for (i = 0; semList[i] != ENDLIST; i++) {
sema = task_sem_group_take_wait(semList); sema = task_sem_group_take_wait(semList);
if (sema != semList[i]) { if (sema != semList[i]) {
TC_ERROR("task_sem_group_take_wait() error. Expected %d, not %d\n", TC_ERROR("task_sem_group_take_wait() error. Expected %d, not %d\n",
(int) semList[i], (int) sema); (int) semList[i], (int) sema);
return TC_FAIL; return TC_FAIL;
}
} }
}
/* /*
* The Alternate Task will signal the semaphore group once. Note that * The Alternate Task will signal the semaphore group once. Note that
* when the semaphore group is signalled, the last semaphore in the * when the semaphore group is signalled, the last semaphore in the
* group is the value that is returned, not the first. * group is the value that is returned, not the first.
*/ */
for (i = 3; i >= 0; i--) { for (i = 3; i >= 0; i--) {
sema = task_sem_group_take_wait(semList); sema = task_sem_group_take_wait(semList);
if (sema != semList[i]) { if (sema != semList[i]) {
TC_ERROR("task_sem_group_take_wait() error. Expected %d, not %d\n", TC_ERROR("task_sem_group_take_wait() error. Expected %d, not %d\n",
(int) semList[3], (int) sema); (int) semList[3], (int) sema);
return TC_FAIL; return TC_FAIL;
}
} }
}
/* /*
* Again wait for a semaphore to be signalled. This time, the alternate * Again wait for a semaphore to be signalled. This time, the alternate
* task will trigger an interrupt that signals the semaphore. * task will trigger an interrupt that signals the semaphore.
*/ */
for (i = 0; semList[i] != ENDLIST; i++) { for (i = 0; semList[i] != ENDLIST; i++) {
sema = task_sem_group_take_wait(semList); sema = task_sem_group_take_wait(semList);
if (sema != semList[i]) { if (sema != semList[i]) {
TC_ERROR("task_sem_group_take_wait() error. Expected %d, not %d\n", TC_ERROR("task_sem_group_take_wait() error. Expected %d, not %d\n",
(int) semList[i], (int) sema); (int) semList[i], (int) sema);
return TC_FAIL; return TC_FAIL;
}
} }
}
return TC_PASS; return TC_PASS;
} }
/******************************************************************************* /*******************************************************************************
* *
@ -382,7 +382,7 @@ int simpleGroupWaitTest(void)
* RETURNS: TC_PASS on success or TC_FAIL on failure * RETURNS: TC_PASS on success or TC_FAIL on failure
*/ */
static int simpleFiberSemTest(void) static int simpleFiberSemTest(void)
{ {
int signalCount; int signalCount;
int status; int status;
int i; int i;
@ -391,36 +391,36 @@ static int simpleFiberSemTest(void)
task_sem_reset(simpleSem); task_sem_reset(simpleSem);
task_sem_group_reset(semList); task_sem_group_reset(semList);
/* let the fiber signal the semaphore and wait on it */ /* let the fiber signal the semaphore and wait on it */
releaseTestFiber(); releaseTestFiber();
status = task_sem_take_wait_timeout(simpleSem, OBJ_TIMEOUT); status = task_sem_take_wait_timeout(simpleSem, OBJ_TIMEOUT);
if (status != RC_OK) { if (status != RC_OK) {
TC_ERROR("task_sem_take_wait_timeout() error. Expected %d, got %d\n", TC_ERROR("task_sem_take_wait_timeout() error. Expected %d, got %d\n",
RC_OK, status); RC_OK, status);
return TC_FAIL; return TC_FAIL;
} }
/* release the fiber and let it signal the semaphore N_TESTS times */ /* release the fiber and let it signal the semaphore N_TESTS times */
releaseTestFiber(); releaseTestFiber();
signalCount = task_sem_count_get(simpleSem); signalCount = task_sem_count_get(simpleSem);
if (signalCount != N_TESTS) { if (signalCount != N_TESTS) {
TC_ERROR("<signalCount> error. Expected %d, got %d\n", TC_ERROR("<signalCount> error. Expected %d, got %d\n",
N_TESTS, signalCount); N_TESTS, signalCount);
return TC_FAIL; return TC_FAIL;
} }
/* wait on the semaphore group while the fiber signals each semaphore in it */ /* wait on the semaphore group while the fiber signals each semaphore in it */
for (i = 0; semList[i] != ENDLIST; i++) { for (i = 0; semList[i] != ENDLIST; i++) {
releaseTestFiber(); releaseTestFiber();
sema = task_sem_group_take_wait_timeout(semList, OBJ_TIMEOUT); sema = task_sem_group_take_wait_timeout(semList, OBJ_TIMEOUT);
if (sema != semList[i]) { if (sema != semList[i]) {
TC_ERROR("task_sem_group_take_wait() error. Expected %d, not %d\n", TC_ERROR("task_sem_group_take_wait() error. Expected %d, not %d\n",
(int) semList[i], (int) sema); (int) semList[i], (int) sema);
return TC_FAIL; return TC_FAIL;
}
} }
return TC_PASS;
} }
return TC_PASS;
}
/******************************************************************************* /*******************************************************************************
* *
@ -430,31 +430,31 @@ static int simpleFiberSemTest(void)
*/ */
int HighPriTask(void) int HighPriTask(void)
{ {
int status; int status;
/* Wait until task is activated */ /* Wait until task is activated */
status = task_sem_take_wait(hpSem); status = task_sem_take_wait(hpSem);
if (status != RC_OK) { if (status != RC_OK) {
TC_ERROR("%s priority task failed to wait on %s: %d\n", TC_ERROR("%s priority task failed to wait on %s: %d\n",
"High", "HIGH_PRI_SEM", status); "High", "HIGH_PRI_SEM", status);
return TC_FAIL; return TC_FAIL;
} }
/* Wait on a semaphore along with other tasks */ /* Wait on a semaphore along with other tasks */
status = task_sem_take_wait(manyBlockSem); status = task_sem_take_wait(manyBlockSem);
if (status != RC_OK) { if (status != RC_OK) {
TC_ERROR("%s priority task failed to wait on %s: %d\n", TC_ERROR("%s priority task failed to wait on %s: %d\n",
"High", "MANY_BLOCKED_SEM", status); "High", "MANY_BLOCKED_SEM", status);
return TC_FAIL; return TC_FAIL;
} }
/* Inform Regression test HP task is no longer blocked on MANY_BLOCKED_SEM*/ /* Inform Regression test HP task is no longer blocked on MANY_BLOCKED_SEM*/
task_sem_give(blockHpSem); task_sem_give(blockHpSem);
return TC_PASS; return TC_PASS;
} }
/******************************************************************************* /*******************************************************************************
* *
@ -464,22 +464,22 @@ int HighPriTask(void)
*/ */
int LowPriTask(void) int LowPriTask(void)
{ {
int status; int status;
/* Wait on a semaphore along with other tasks */ /* Wait on a semaphore along with other tasks */
status = task_sem_take_wait(manyBlockSem); status = task_sem_take_wait(manyBlockSem);
if (status != RC_OK) { if (status != RC_OK) {
TC_ERROR("%s priority task failed to wait on %s: %d\n", TC_ERROR("%s priority task failed to wait on %s: %d\n",
"Low", "MANY_BLOCKED_SEM", status); "Low", "MANY_BLOCKED_SEM", status);
return TC_FAIL; return TC_FAIL;
} }
/* Inform Regression test LP task is no longer blocked on MANY_BLOCKED_SEM*/ /* Inform Regression test LP task is no longer blocked on MANY_BLOCKED_SEM*/
task_sem_give(blockLpSem); task_sem_give(blockLpSem);
return TC_PASS; return TC_PASS;
} }
/******************************************************************************* /*******************************************************************************
* *
@ -491,74 +491,74 @@ int LowPriTask(void)
*/ */
int AlternateTask(void) int AlternateTask(void)
{ {
int status; int status;
int i; int i;
/* Wait until it is time to continue */ /* Wait until it is time to continue */
status = task_sem_take_wait(altSem); status = task_sem_take_wait(altSem);
if (status != RC_OK) { if (status != RC_OK) {
TC_ERROR("task_sem_take_wait() error. Expected %d, got %d\n", TC_ERROR("task_sem_take_wait() error. Expected %d, got %d\n",
RC_OK, status); RC_OK, status);
return TC_FAIL; return TC_FAIL;
} }
/* /*
* After signalling the semaphore upon which the main (RegressionTask) task * After signalling the semaphore upon which the main (RegressionTask) task
* is waiting, control will pass back to the main (RegressionTask) task. * is waiting, control will pass back to the main (RegressionTask) task.
*/ */
task_sem_give(simpleSem); task_sem_give(simpleSem);
/* /*
* Control has returned to the alternate task. Trigger an ISR that will * Control has returned to the alternate task. Trigger an ISR that will
* signal the semaphore upon which RegressionTask is waiting. * signal the semaphore upon which RegressionTask is waiting.
*/ */
trigger_isrSemaSignal(simpleSem); trigger_isrSemaSignal(simpleSem);
/* Wait for RegressionTask to wake this task up */ /* Wait for RegressionTask to wake this task up */
status = task_sem_take_wait(altSem); status = task_sem_take_wait(altSem);
if (status != RC_OK) { if (status != RC_OK) {
TC_ERROR("task_sem_take_wait() error. Expected %d, got %d", TC_ERROR("task_sem_take_wait() error. Expected %d, got %d",
RC_OK, status); RC_OK, status);
return TC_FAIL; return TC_FAIL;
} }
/* Wait on a semaphore that will have many waiters */ /* Wait on a semaphore that will have many waiters */
status = task_sem_take_wait(manyBlockSem); status = task_sem_take_wait(manyBlockSem);
if (status != RC_OK) { if (status != RC_OK) {
TC_ERROR("task_sem_take_wait() error. Expected %d, got %d", TC_ERROR("task_sem_take_wait() error. Expected %d, got %d",
RC_OK, status); RC_OK, status);
return TC_FAIL; return TC_FAIL;
} }
/* Inform Regression test MP task is no longer blocked on MANY_BLOCKED_SEM*/ /* Inform Regression test MP task is no longer blocked on MANY_BLOCKED_SEM*/
task_sem_give(blockMpSem); task_sem_give(blockMpSem);
/* Wait until the alternate task is needed again */ /* Wait until the alternate task is needed again */
status = task_sem_take_wait(altSem); status = task_sem_take_wait(altSem);
if (status != RC_OK) { if (status != RC_OK) {
TC_ERROR("task_sem_take_wait() error. Expected %d, got %d", TC_ERROR("task_sem_take_wait() error. Expected %d, got %d",
RC_OK, status); RC_OK, status);
return TC_FAIL; return TC_FAIL;
} }
for (i = 0; semList[i] != ENDLIST; i++) { for (i = 0; semList[i] != ENDLIST; i++) {
task_sem_give(semList[i]); task_sem_give(semList[i]);
/* Context switch back to Regression Task */ /* Context switch back to Regression Task */
} }
task_sem_group_give(semList); task_sem_group_give(semList);
/* Context switch back to Regression Task */ /* Context switch back to Regression Task */
for (i = 0; semList[i] != ENDLIST; i++) { for (i = 0; semList[i] != ENDLIST; i++) {
trigger_isrSemaSignal(semList[i]); trigger_isrSemaSignal(semList[i]);
/* Context switch back to Regression Task */ /* Context switch back to Regression Task */
} }
return TC_PASS; return TC_PASS;
} }
/******************************************************************************* /*******************************************************************************
* *
@ -570,7 +570,7 @@ int AlternateTask(void)
*/ */
int RegressionTask(void) int RegressionTask(void)
{ {
int tcRC; int tcRC;
int value; int value;
ksem_t semBlockList[4]; ksem_t semBlockList[4];
@ -580,31 +580,31 @@ int RegressionTask(void)
semBlockList[2] = blockLpSem; semBlockList[2] = blockLpSem;
semBlockList[3] = ENDLIST; semBlockList[3] = ENDLIST;
/* Signal a semaphore that has no waiting tasks. */ /* Signal a semaphore that has no waiting tasks. */
TC_PRINT("Signal and test a semaphore without blocking\n"); TC_PRINT("Signal and test a semaphore without blocking\n");
tcRC = simpleSemaTest(); tcRC = simpleSemaTest();
if (tcRC != TC_PASS) { if (tcRC != TC_PASS) {
return TC_FAIL; return TC_FAIL;
} }
/* Wait on a semaphore. */ /* Wait on a semaphore. */
TC_PRINT("Signal and test a semaphore with blocking\n"); TC_PRINT("Signal and test a semaphore with blocking\n");
tcRC = simpleSemaWaitTest(); tcRC = simpleSemaWaitTest();
if (tcRC != TC_PASS) { if (tcRC != TC_PASS) {
return TC_FAIL; return TC_FAIL;
} }
/* /*
* Have many tasks wait on a semaphore (MANY_BLOCKED_SEM). They will * Have many tasks wait on a semaphore (MANY_BLOCKED_SEM). They will
* block in the following order: * block in the following order:
* LowPriorityTask (low priority) * LowPriorityTask (low priority)
* HighPriorityTask (high priority) * HighPriorityTask (high priority)
* AlternateTask (medium priority) * AlternateTask (medium priority)
* *
* When the semaphore (MANY_BLOCKED_SEM) is signalled, HighPriorityTask * When the semaphore (MANY_BLOCKED_SEM) is signalled, HighPriorityTask
* will be woken first. * will be woken first.
* *
*/ */
TC_PRINT("Testing many tasks blocked on the same semaphore\n"); TC_PRINT("Testing many tasks blocked on the same semaphore\n");
@ -619,18 +619,18 @@ int RegressionTask(void)
value = task_sem_group_take_wait_timeout(semBlockList, OBJ_TIMEOUT); value = task_sem_group_take_wait_timeout(semBlockList, OBJ_TIMEOUT);
if (value != blockHpSem) { if (value != blockHpSem) {
TC_ERROR("%s priority task did not get semaphore: 0x%x\n", TC_ERROR("%s priority task did not get semaphore: 0x%x\n",
"High", value); "High", value);
return TC_FAIL; return TC_FAIL;
} }
task_sem_give(manyBlockSem); task_sem_give(manyBlockSem);
task_sleep(OBJ_TIMEOUT); /* Ensure medium priority task can run */ task_sleep(OBJ_TIMEOUT); /* Ensure medium priority task can run */
value = task_sem_group_take_wait_timeout(semBlockList, OBJ_TIMEOUT); value = task_sem_group_take_wait_timeout(semBlockList, OBJ_TIMEOUT);
if (value != blockMpSem) { if (value != blockMpSem) {
TC_ERROR("%s priority task did not get semaphore: 0x%x\n", TC_ERROR("%s priority task did not get semaphore: 0x%x\n",
"Medium", value); "Medium", value);
return TC_FAIL; return TC_FAIL;
} }
task_sem_give(manyBlockSem); task_sem_give(manyBlockSem);
@ -639,35 +639,35 @@ int RegressionTask(void)
value = task_sem_group_take_wait_timeout(semBlockList, OBJ_TIMEOUT); value = task_sem_group_take_wait_timeout(semBlockList, OBJ_TIMEOUT);
if (value != blockLpSem) { if (value != blockLpSem) {
TC_ERROR("%s priority task did not get semaphore: 0x%x\n", TC_ERROR("%s priority task did not get semaphore: 0x%x\n",
"Low", value); "Low", value);
return TC_FAIL; return TC_FAIL;
} }
value = task_sem_group_take_wait_timeout(semBlockList, OBJ_TIMEOUT); value = task_sem_group_take_wait_timeout(semBlockList, OBJ_TIMEOUT);
if (value != ENDLIST) { if (value != ENDLIST) {
TC_ERROR("Group test Expecting ENDLIST, but got 0x%x\n", TC_ERROR("Group test Expecting ENDLIST, but got 0x%x\n",
value); value);
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT("Testing semaphore groups without blocking\n"); TC_PRINT("Testing semaphore groups without blocking\n");
tcRC = simpleGroupTest(); tcRC = simpleGroupTest();
if (tcRC != TC_PASS) { if (tcRC != TC_PASS) {
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT("Testing semaphore groups with blocking\n"); TC_PRINT("Testing semaphore groups with blocking\n");
tcRC = simpleGroupWaitTest(); tcRC = simpleGroupWaitTest();
if (tcRC != TC_PASS) { if (tcRC != TC_PASS) {
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT("Testing semaphore release by fiber\n"); TC_PRINT("Testing semaphore release by fiber\n");
tcRC = simpleFiberSemTest(); tcRC = simpleFiberSemTest();
if (tcRC != TC_PASS) { if (tcRC != TC_PASS) {
return TC_FAIL; return TC_FAIL;
} }
return TC_PASS; return TC_PASS;
} }

View file

@ -72,24 +72,24 @@ static CMD_PKT_SET_INSTANCE(cmdPktSet, N_TESTS + 1)
* RETURNS: N/A * RETURNS: N/A
*/ */
static void testFiberEntry(void) static void testFiberEntry(void)
{ {
int i; int i;
/* release semaphore test task is waiting for */ /* release semaphore test task is waiting for */
nano_fiber_sem_take_wait(&fiberSem); nano_fiber_sem_take_wait(&fiberSem);
fiber_sem_give(simpleSem, &CMD_PKT_SET(cmdPktSet)); fiber_sem_give(simpleSem, &CMD_PKT_SET(cmdPktSet));
/* release the semaphore for N_TESTS times */ /* release the semaphore for N_TESTS times */
nano_fiber_sem_take_wait(&fiberSem); nano_fiber_sem_take_wait(&fiberSem);
for (i = 0; i < N_TESTS; i++) { for (i = 0; i < N_TESTS; i++) {
fiber_sem_give(simpleSem, &CMD_PKT_SET(cmdPktSet)); fiber_sem_give(simpleSem, &CMD_PKT_SET(cmdPktSet));
} }
/* signal each semaphore in the group */ /* signal each semaphore in the group */
for (i = 0; semList[i] != ENDLIST; i++) { for (i = 0; semList[i] != ENDLIST; i++) {
nano_fiber_sem_take_wait(&fiberSem); nano_fiber_sem_take_wait(&fiberSem);
fiber_sem_give(semList[i], &CMD_PKT_SET(cmdPktSet)); fiber_sem_give(semList[i], &CMD_PKT_SET(cmdPktSet));
}
} }
}
/******************************************************************************* /*******************************************************************************
* *
@ -99,8 +99,8 @@ static void testFiberEntry(void)
*/ */
void testFiberInit(void) void testFiberInit(void)
{ {
nano_sem_init(&fiberSem); nano_sem_init(&fiberSem);
task_fiber_start(fiberStack, FIBER_STACK_SIZE, (nano_fiber_entry_t)testFiberEntry, task_fiber_start(fiberStack, FIBER_STACK_SIZE, (nano_fiber_entry_t)testFiberEntry,
0, 0, FIBER_PRIORITY, 0); 0, 0, FIBER_PRIORITY, 0);
} }

View file

@ -75,8 +75,8 @@ typedef union {
struct { struct {
uint32_t u1; /* This part contains the exponent */ uint32_t u1; /* This part contains the exponent */
uint32_t u2; /* This part contains the fraction */ uint32_t u2; /* This part contains the fraction */
}; };
} raw_double_u; } raw_double_u;
#ifdef CONFIG_FLOAT #ifdef CONFIG_FLOAT
/******************************************************************************* /*******************************************************************************
@ -98,7 +98,7 @@ int sprintfDoubleTest(void)
if (strcmp(buffer, "+INF") != 0) { if (strcmp(buffer, "+INF") != 0) {
TC_ERROR("sprintf(+INF) - incorrect output '%s'\n", buffer); TC_ERROR("sprintf(+INF) - incorrect output '%s'\n", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
var.u1 = 0x00000000; var.u1 = 0x00000000;
var.u2 = 0xfff00000; /* Bit pattern for -INF (double) */ var.u2 = 0xfff00000; /* Bit pattern for -INF (double) */
@ -106,7 +106,7 @@ int sprintfDoubleTest(void)
if (strcmp(buffer, "-INF") != 0) { if (strcmp(buffer, "-INF") != 0) {
TC_ERROR("sprintf(-INF) - incorrect output '%s'\n", buffer); TC_ERROR("sprintf(-INF) - incorrect output '%s'\n", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
var.u1 = 0x00000000; var.u1 = 0x00000000;
var.u2 = 0x7ff80000; /* Bit pattern for NaN (double) */ var.u2 = 0x7ff80000; /* Bit pattern for NaN (double) */
@ -114,123 +114,122 @@ int sprintfDoubleTest(void)
if (strcmp(buffer, "NaN") != 0) { if (strcmp(buffer, "NaN") != 0) {
TC_ERROR("sprintf(NaN) - incorrect output '%s'\n", buffer); TC_ERROR("sprintf(NaN) - incorrect output '%s'\n", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
var.d = 1.0; var.d = 1.0;
sprintf(buffer, "%f", var.d); sprintf(buffer, "%f", var.d);
if (strcmp(buffer, "1.000000") != 0) { if (strcmp(buffer, "1.000000") != 0) {
TC_ERROR("sprintf(1.0) - incorrect output '%s'\n", buffer); TC_ERROR("sprintf(1.0) - incorrect output '%s'\n", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
sprintf(buffer, "%+f", var.d); sprintf(buffer, "%+f", var.d);
if (strcmp(buffer, "+1.000000") != 0) { if (strcmp(buffer, "+1.000000") != 0) {
TC_ERROR("sprintf(+1.0) - incorrect output '%s'\n", buffer); TC_ERROR("sprintf(+1.0) - incorrect output '%s'\n", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
sprintf(buffer, "%.2f", var.d); sprintf(buffer, "%.2f", var.d);
if (strcmp(buffer, "1.00") != 0) { if (strcmp(buffer, "1.00") != 0) {
TC_ERROR("sprintf(1.00) - incorrect output '%s'\n", buffer); TC_ERROR("sprintf(1.00) - incorrect output '%s'\n", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
sprintf(buffer, "%.*f", 11, var.d); sprintf(buffer, "%.*f", 11, var.d);
if (strcmp(buffer, "1.00000000000") != 0) { if (strcmp(buffer, "1.00000000000") != 0) {
TC_ERROR("sprintf(1.00000000000) - incorrect output '%s'\n", buffer); TC_ERROR("sprintf(1.00000000000) - incorrect output '%s'\n", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
sprintf(buffer, "%12f", var.d); sprintf(buffer, "%12f", var.d);
if (strcmp(buffer, " 1.000000") != 0) { if (strcmp(buffer, " 1.000000") != 0) {
TC_ERROR("sprintf( 1.000000) - incorrect output '%s'\n", buffer); TC_ERROR("sprintf( 1.000000) - incorrect output '%s'\n", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
sprintf(buffer, "%-12f", var.d); sprintf(buffer, "%-12f", var.d);
if (strcmp(buffer, "1.000000 ") != 0) { if (strcmp(buffer, "1.000000 ") != 0) {
TC_ERROR("sprintf(1.000000 ) - incorrect output '%s'\n", buffer); TC_ERROR("sprintf(1.000000 ) - incorrect output '%s'\n", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
sprintf(buffer, "%012f", var.d); sprintf(buffer, "%012f", var.d);
if (strcmp(buffer, "00001.000000") != 0) { if (strcmp(buffer, "00001.000000") != 0) {
TC_ERROR("sprintf(00001.000000) - incorrect output '%s'\n", buffer); TC_ERROR("sprintf(00001.000000) - incorrect output '%s'\n", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
var.d = -1.0; var.d = -1.0;
sprintf(buffer, "%f", var.d); sprintf(buffer, "%f", var.d);
if (strcmp(buffer, "-1.000000") != 0) { if (strcmp(buffer, "-1.000000") != 0) {
TC_ERROR("sprintf(-1.0) - incorrect output '%s'\n", buffer); TC_ERROR("sprintf(-1.0) - incorrect output '%s'\n", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
var.d = 1234.56789; var.d = 1234.56789;
sprintf(buffer, "%f", var.d); sprintf(buffer, "%f", var.d);
if (strcmp(buffer, "1234.567890") != 0) { if (strcmp(buffer, "1234.567890") != 0) {
TC_ERROR("sprintf(-1.0) - incorrect output '%s'\n", buffer); TC_ERROR("sprintf(-1.0) - incorrect output '%s'\n", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
/*******************/ /*******************/
var.d = 1234.0; var.d = 1234.0;
sprintf(buffer, "%e", var.d); sprintf(buffer, "%e", var.d);
if (strcmp(buffer, "1.234000e+003") != 0) { if (strcmp(buffer, "1.234000e+003") != 0) {
TC_ERROR("sprintf(1.234000e+003) - incorrect output '%s'\n", buffer); TC_ERROR("sprintf(1.234000e+003) - incorrect output '%s'\n", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
sprintf(buffer, "%E", var.d); sprintf(buffer, "%E", var.d);
if (strcmp(buffer, "1.234000E+003") != 0) { if (strcmp(buffer, "1.234000E+003") != 0) {
TC_ERROR("sprintf(1.234000E+003) - incorrect output '%s'\n", buffer); TC_ERROR("sprintf(1.234000E+003) - incorrect output '%s'\n", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
/*******************/ /*******************/
var.d = 0.1234; var.d = 0.1234;
sprintf(buffer, "%e", var.d); sprintf(buffer, "%e", var.d);
if (strcmp(buffer, "1.234000e-001") != 0) { if (strcmp(buffer, "1.234000e-001") != 0) {
TC_ERROR("sprintf(1.234000e-001) - incorrect output '%s'\n", buffer); TC_ERROR("sprintf(1.234000e-001) - incorrect output '%s'\n", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
sprintf(buffer, "%E", var.d); sprintf(buffer, "%E", var.d);
if (strcmp(buffer, "1.234000E-001") != 0) { if (strcmp(buffer, "1.234000E-001") != 0) {
TC_ERROR("sprintf(1.234000E-001) - incorrect output '%s'\n", buffer); TC_ERROR("sprintf(1.234000E-001) - incorrect output '%s'\n", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
/*******************/ /*******************/
var.d = 1234000000.0; var.d = 1234000000.0;
sprintf(buffer, "%g", var.d); sprintf(buffer, "%g", var.d);
if (strcmp(buffer, "1.234e+009") != 0) { if (strcmp(buffer, "1.234e+009") != 0) {
TC_ERROR("sprintf(1.234e+009) - incorrect output '%s'\n", buffer); TC_ERROR("sprintf(1.234e+009) - incorrect output '%s'\n", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
sprintf(buffer, "%G", var.d); sprintf(buffer, "%G", var.d);
if (strcmp(buffer, "1.234E+009") != 0) { if (strcmp(buffer, "1.234E+009") != 0) {
TC_ERROR("sprintf(1.234E+009) - incorrect output '%s'\n", buffer); TC_ERROR("sprintf(1.234E+009) - incorrect output '%s'\n", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
/*******************/ /*******************/
/* /*
* VxMicro does not support size modifiers such as L. As such, attempts to * VxMicro does not support size modifiers such as L. As such, attempts to
* print a long double will NOT result in intuitively expected output. * print a long double will NOT result in intuitively expected output.
* Until such time as they are supported (if ever) the output will remain * Until such time as they are supported (if ever) the output will remain
* counter-intuitive. If they ever are supported then this test will have * counter-intuitive. If they ever are supported then this test will have
* to be updated. * to be updated.
*/ */
sprintf(buffer, "%Lf", (long double) 1234567.0); sprintf(buffer, "%Lf", (long double) 1234567.0);
if (strcmp("-0.000000", buffer) != 0) { if (strcmp("-0.000000", buffer) != 0) {
TC_ERROR("sprintf(%%Lf). Expected '-0.000000', got '%s'\n", TC_ERROR("sprintf(%%Lf). Expected '-0.000000', got '%s'\n", buffer);
buffer);
status = TC_FAIL; status = TC_FAIL;
} }
return status; return status;
} }
@ -271,55 +270,55 @@ int vsnprintfTest(void)
int status = TC_PASS; int status = TC_PASS;
char buffer[100]; char buffer[100];
/* /*
* VxMicro may be handling the string size in a non-standard manner. * VxMicro may be handling the string size in a non-standard manner.
* If a negative value is supplied for the string size, VxMicro converts * If a negative value is supplied for the string size, VxMicro converts
* it to 0x7fffffff--maximum integer size. Since there is insufficient * it to 0x7fffffff--maximum integer size. Since there is insufficient
* memory to test a string of that length, we just check that the string * memory to test a string of that length, we just check that the string
* was fully written so that we can exercise the code path. * was fully written so that we can exercise the code path.
*/ */
buffer[0] = '\0'; buffer[0] = '\0';
len = tvsnprintf(buffer, (size_t)(-4), "%x", DEADBEEF); len = tvsnprintf(buffer, (size_t)(-4), "%x", DEADBEEF);
if (len != strlen(DEADBEEF_LHEX_STR)) { if (len != strlen(DEADBEEF_LHEX_STR)) {
TC_ERROR("vsnprintf(%%x). Expected return value %d, not %d\n", TC_ERROR("vsnprintf(%%x). Expected return value %d, not %d\n",
strlen(DEADBEEF_LHEX_STR), len); strlen(DEADBEEF_LHEX_STR), len);
status = TC_FAIL; status = TC_FAIL;
} }
if (strcmp(buffer, DEADBEEF_LHEX_STR) != 0) { if (strcmp(buffer, DEADBEEF_LHEX_STR) != 0) {
TC_ERROR("vsnprintf(%%x). Expected '%s', got '%s'\n", TC_ERROR("vsnprintf(%%x). Expected '%s', got '%s'\n",
DEADBEEF_LHEX_STR, buffer); DEADBEEF_LHEX_STR, buffer);
status = TC_FAIL; status = TC_FAIL;
} }
/*******************/ /*******************/
buffer[0] = '\0'; buffer[0] = '\0';
len = tvsnprintf(buffer, 0, "%x", DEADBEEF); len = tvsnprintf(buffer, 0, "%x", DEADBEEF);
if (len != strlen(DEADBEEF_LHEX_STR)) { if (len != strlen(DEADBEEF_LHEX_STR)) {
TC_ERROR("vsnprintf(%%x). Expected return value %d, not %d\n", TC_ERROR("vsnprintf(%%x). Expected return value %d, not %d\n",
strlen(DEADBEEF_LHEX_STR), len); strlen(DEADBEEF_LHEX_STR), len);
status = TC_FAIL; status = TC_FAIL;
} }
if (strcmp(buffer, "") != 0) { if (strcmp(buffer, "") != 0) {
TC_ERROR("vsnprintf(%%x). Expected '%s', got '%s'\n", TC_ERROR("vsnprintf(%%x). Expected '%s', got '%s'\n",
"", buffer); "", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
/*******************/ /*******************/
len = tvsnprintf(buffer, 4, "%x", DEADBEEF); len = tvsnprintf(buffer, 4, "%x", DEADBEEF);
if (len != strlen(DEADBEEF_LHEX_STR)) { if (len != strlen(DEADBEEF_LHEX_STR)) {
TC_ERROR("vsnprintf(%%x). Expected return value %d, not %d\n", TC_ERROR("vsnprintf(%%x). Expected return value %d, not %d\n",
strlen(DEADBEEF_LHEX_STR), len); strlen(DEADBEEF_LHEX_STR), len);
status = TC_FAIL; status = TC_FAIL;
} }
if (strcmp(buffer, "dea") != 0) { if (strcmp(buffer, "dea") != 0) {
TC_ERROR("vsnprintf(%%x). Expected '%s', got '%s'\n", TC_ERROR("vsnprintf(%%x). Expected '%s', got '%s'\n",
"dea", buffer); "dea", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
return status; return status;
} }
@ -358,19 +357,19 @@ int vsprintfTest(void)
int status = TC_PASS; int status = TC_PASS;
char buffer[100]; char buffer[100];
/*******************/ /*******************/
len = tvsprintf(buffer, "%x", DEADBEEF); len = tvsprintf(buffer, "%x", DEADBEEF);
if (len != strlen(DEADBEEF_LHEX_STR)) { if (len != strlen(DEADBEEF_LHEX_STR)) {
TC_ERROR("sprintf(%%x). Expected %d bytes written, not %d\n", TC_ERROR("sprintf(%%x). Expected %d bytes written, not %d\n",
strlen(DEADBEEF_LHEX_STR), len); strlen(DEADBEEF_LHEX_STR), len);
status = TC_FAIL; status = TC_FAIL;
} }
if (strcmp(buffer, DEADBEEF_LHEX_STR) != 0) { if (strcmp(buffer, DEADBEEF_LHEX_STR) != 0) {
TC_ERROR("sprintf(%%x). Expected '%s', got '%s'\n", TC_ERROR("sprintf(%%x). Expected '%s', got '%s'\n",
DEADBEEF_LHEX_STR, buffer); DEADBEEF_LHEX_STR, buffer);
status = TC_FAIL; status = TC_FAIL;
} }
return status; return status;
} }
@ -392,55 +391,55 @@ int snprintfTest(void)
int status = TC_PASS; int status = TC_PASS;
char buffer[100]; char buffer[100];
/* /*
* VxMicro may be handling the string size in a non-standard manner. * VxMicro may be handling the string size in a non-standard manner.
* If a negative value is supplied for the string size, VxMicro converts * If a negative value is supplied for the string size, VxMicro converts
* it to 0x7fffffff--maximum integer size. Since there is insufficient * it to 0x7fffffff--maximum integer size. Since there is insufficient
* memory to test a string of that length, we just check that the string * memory to test a string of that length, we just check that the string
* was fully written so that we can exercise the code path. * was fully written so that we can exercise the code path.
*/ */
buffer[0] = '\0'; buffer[0] = '\0';
len = snprintf(buffer, (size_t)(-4), "%x", DEADBEEF); len = snprintf(buffer, (size_t)(-4), "%x", DEADBEEF);
if (len != strlen(DEADBEEF_LHEX_STR)) { if (len != strlen(DEADBEEF_LHEX_STR)) {
TC_ERROR("snprintf(%%x). Expected return value %d, not %d\n", TC_ERROR("snprintf(%%x). Expected return value %d, not %d\n",
strlen(DEADBEEF_LHEX_STR), len); strlen(DEADBEEF_LHEX_STR), len);
status = TC_FAIL; status = TC_FAIL;
} }
if (strcmp(buffer, DEADBEEF_LHEX_STR) != 0) { if (strcmp(buffer, DEADBEEF_LHEX_STR) != 0) {
TC_ERROR("snprintf(%%x). Expected '%s', got '%s'\n", TC_ERROR("snprintf(%%x). Expected '%s', got '%s'\n",
DEADBEEF_LHEX_STR, buffer); DEADBEEF_LHEX_STR, buffer);
status = TC_FAIL; status = TC_FAIL;
} }
/*******************/ /*******************/
buffer[0] = '\0'; buffer[0] = '\0';
len = snprintf(buffer, 0, "%x", DEADBEEF); len = snprintf(buffer, 0, "%x", DEADBEEF);
if (len != strlen(DEADBEEF_LHEX_STR)) { if (len != strlen(DEADBEEF_LHEX_STR)) {
TC_ERROR("snprintf(%%x). Expected return value %d, not %d\n", TC_ERROR("snprintf(%%x). Expected return value %d, not %d\n",
strlen(DEADBEEF_LHEX_STR), len); strlen(DEADBEEF_LHEX_STR), len);
status = TC_FAIL; status = TC_FAIL;
} }
if (strcmp(buffer, "") != 0) { if (strcmp(buffer, "") != 0) {
TC_ERROR("snprintf(%%x). Expected '%s', got '%s'\n", TC_ERROR("snprintf(%%x). Expected '%s', got '%s'\n",
"", buffer); "", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
/*******************/ /*******************/
len = snprintf(buffer, 4, "%x", DEADBEEF); len = snprintf(buffer, 4, "%x", DEADBEEF);
if (len != strlen(DEADBEEF_LHEX_STR)) { if (len != strlen(DEADBEEF_LHEX_STR)) {
TC_ERROR("snprintf(%%x). Expected return value %d, not %d\n", TC_ERROR("snprintf(%%x). Expected return value %d, not %d\n",
strlen(DEADBEEF_LHEX_STR), len); strlen(DEADBEEF_LHEX_STR), len);
status = TC_FAIL; status = TC_FAIL;
} }
if (strcmp(buffer, "dea") != 0) { if (strcmp(buffer, "dea") != 0) {
TC_ERROR("snprintf(%%x). Expected '%s', got '%s'\n", TC_ERROR("snprintf(%%x). Expected '%s', got '%s'\n",
"dea", buffer); "dea", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
return status; return status;
} }
@ -458,65 +457,65 @@ int sprintfMiscTest(void)
int count; int count;
char buffer[100]; char buffer[100];
/*******************/ /*******************/
sprintf(buffer, "%p", (void *) DEADBEEF); sprintf(buffer, "%p", (void *) DEADBEEF);
if (strcmp(buffer, DEADBEEF_PTR_STR) != 0) { if (strcmp(buffer, DEADBEEF_PTR_STR) != 0) {
TC_ERROR("sprintf(%%p). Expected '%s', got '%s'\n", TC_ERROR("sprintf(%%p). Expected '%s', got '%s'\n",
DEADBEEF_PTR_STR, buffer); DEADBEEF_PTR_STR, buffer);
status = TC_FAIL; status = TC_FAIL;
} }
/*******************/ /*******************/
sprintf(buffer, "test data %n test data", &count); sprintf(buffer, "test data %n test data", &count);
if (count != 10) { if (count != 10) {
TC_ERROR("sprintf(%%n). Expected count to be %d, not %d\n", TC_ERROR("sprintf(%%n). Expected count to be %d, not %d\n",
10, count); 10, count);
status = TC_FAIL; status = TC_FAIL;
} }
if (strcmp(buffer, "test data test data") != 0) { if (strcmp(buffer, "test data test data") != 0) {
TC_ERROR("sprintf(%%p). Expected '%s', got '%s'\n", TC_ERROR("sprintf(%%p). Expected '%s', got '%s'\n",
"test data test data", buffer); "test data test data", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
/*******************/ /*******************/
sprintf(buffer, "%*d", 10, 1234); sprintf(buffer, "%*d", 10, 1234);
if (strcmp(buffer, " 1234") != 0) { if (strcmp(buffer, " 1234") != 0) {
TC_ERROR("sprintf(%%p). Expected '%s', got '%s'\n", TC_ERROR("sprintf(%%p). Expected '%s', got '%s'\n",
" 1234", buffer); " 1234", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
/*******************/ /*******************/
sprintf(buffer, "%*d", -10, 1234); sprintf(buffer, "%*d", -10, 1234);
if (strcmp(buffer, "1234 ") != 0) { if (strcmp(buffer, "1234 ") != 0) {
TC_ERROR("sprintf(%%p). Expected '%s', got '%s'\n", TC_ERROR("sprintf(%%p). Expected '%s', got '%s'\n",
"1234 ", buffer); "1234 ", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
/*******************/ /*******************/
sprintf(buffer, "% d", 1234); sprintf(buffer, "% d", 1234);
if (strcmp(buffer, " 1234") != 0) { if (strcmp(buffer, " 1234") != 0) {
TC_ERROR("sprintf(%% d). Expected '%s', got '%s'\n", TC_ERROR("sprintf(%% d). Expected '%s', got '%s'\n",
" 1234", buffer); " 1234", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
/*******************/ /*******************/
sprintf(buffer, "%hx", 1234); sprintf(buffer, "%hx", 1234);
if (strcmp("4d2", buffer) != 0) { if (strcmp("4d2", buffer) != 0) {
TC_ERROR("sprintf(%%hx). Expected '4d2', got '%s'\n", buffer); TC_ERROR("sprintf(%%hx). Expected '4d2', got '%s'\n", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
/*******************/ /*******************/
sprintf(buffer, "%lx", 1234ul); sprintf(buffer, "%lx", 1234ul);
if (strcmp("4d2", buffer) != 0) { if (strcmp("4d2", buffer) != 0) {
TC_ERROR("sprintf(%%lx). Expected '4d2', got '%s'\n", buffer); TC_ERROR("sprintf(%%lx). Expected '4d2', got '%s'\n", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
return status; return status;
} }
@ -534,142 +533,142 @@ int sprintfIntegerTest(void)
int len; int len;
char buffer[100]; char buffer[100];
/*******************/ /*******************/
/* Note: VxMicro prints hex numbers in 8 characters */ /* Note: VxMicro prints hex numbers in 8 characters */
len = sprintf(buffer, "%x", 0x11); len = sprintf(buffer, "%x", 0x11);
if (len != 2) { if (len != 2) {
TC_ERROR("sprintf(%%x). Expected 2 bytes written, not %d\n", len); TC_ERROR("sprintf(%%x). Expected 2 bytes written, not %d\n", len);
status = TC_FAIL; status = TC_FAIL;
} }
if (strcmp(buffer, "11") != 0) { if (strcmp(buffer, "11") != 0) {
TC_ERROR("sprintf(%%x). Expected '%s', got '%s'\n", "11", buffer); TC_ERROR("sprintf(%%x). Expected '%s', got '%s'\n", "11", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
/*******************/ /*******************/
len = sprintf(buffer, "%x", DEADBEEF); len = sprintf(buffer, "%x", DEADBEEF);
if (len != strlen(DEADBEEF_LHEX_STR)) { if (len != strlen(DEADBEEF_LHEX_STR)) {
TC_ERROR("sprintf(%%x). Expected %d bytes written, not %d\n", TC_ERROR("sprintf(%%x). Expected %d bytes written, not %d\n",
strlen(DEADBEEF_LHEX_STR), len); strlen(DEADBEEF_LHEX_STR), len);
status = TC_FAIL; status = TC_FAIL;
} }
if (strcmp(buffer, DEADBEEF_LHEX_STR) != 0) { if (strcmp(buffer, DEADBEEF_LHEX_STR) != 0) {
TC_ERROR("sprintf(%%x). Expected '%s', got '%s'\n", TC_ERROR("sprintf(%%x). Expected '%s', got '%s'\n",
DEADBEEF_LHEX_STR, buffer); DEADBEEF_LHEX_STR, buffer);
status = TC_FAIL; status = TC_FAIL;
} }
/*******************/ /*******************/
len = sprintf(buffer, "%X", DEADBEEF); len = sprintf(buffer, "%X", DEADBEEF);
if (len != strlen(DEADBEEF_UHEX_STR)) { if (len != strlen(DEADBEEF_UHEX_STR)) {
TC_ERROR("sprintf(%%X). Expected %d bytes written, not %d\n", TC_ERROR("sprintf(%%X). Expected %d bytes written, not %d\n",
strlen(DEADBEEF_UHEX_STR), len); strlen(DEADBEEF_UHEX_STR), len);
status = TC_FAIL; status = TC_FAIL;
} }
if (strcmp(buffer, DEADBEEF_UHEX_STR) != 0) { if (strcmp(buffer, DEADBEEF_UHEX_STR) != 0) {
TC_ERROR("sprintf(%%X). Expected '%s', got '%s'\n", TC_ERROR("sprintf(%%X). Expected '%s', got '%s'\n",
DEADBEEF_UHEX_STR, buffer); DEADBEEF_UHEX_STR, buffer);
status = TC_FAIL; status = TC_FAIL;
} }
/*******************/ /*******************/
len = sprintf(buffer, "%u", DEADBEEF); len = sprintf(buffer, "%u", DEADBEEF);
if (len != strlen(DEADBEEF_UNSIGNED_STR)) { if (len != strlen(DEADBEEF_UNSIGNED_STR)) {
TC_ERROR("sprintf(%%u). Expected %d bytes written, not %d\n", TC_ERROR("sprintf(%%u). Expected %d bytes written, not %d\n",
strlen(DEADBEEF_UNSIGNED_STR), len); strlen(DEADBEEF_UNSIGNED_STR), len);
status = TC_FAIL; status = TC_FAIL;
} }
if (strcmp(buffer, DEADBEEF_UNSIGNED_STR) != 0) { if (strcmp(buffer, DEADBEEF_UNSIGNED_STR) != 0) {
TC_ERROR("sprintf(%%u). Expected '%s', got '%s'\n", TC_ERROR("sprintf(%%u). Expected '%s', got '%s'\n",
DEADBEEF_UNSIGNED_STR, buffer); DEADBEEF_UNSIGNED_STR, buffer);
status = TC_FAIL; status = TC_FAIL;
} }
/*******************/ /*******************/
len = sprintf(buffer, "%d", (int) DEADBEEF); len = sprintf(buffer, "%d", (int) DEADBEEF);
if (len != strlen(DEADBEEF_SIGNED_STR)) { if (len != strlen(DEADBEEF_SIGNED_STR)) {
TC_ERROR("sprintf(%%d). Expected %d bytes written, not %d\n", TC_ERROR("sprintf(%%d). Expected %d bytes written, not %d\n",
strlen(DEADBEEF_SIGNED_STR), len); strlen(DEADBEEF_SIGNED_STR), len);
status = TC_FAIL; status = TC_FAIL;
} }
if (strcmp(buffer, DEADBEEF_SIGNED_STR) != 0) { if (strcmp(buffer, DEADBEEF_SIGNED_STR) != 0) {
TC_ERROR("sprintf(%%d). Expected '%s', got '%s'\n", TC_ERROR("sprintf(%%d). Expected '%s', got '%s'\n",
DEADBEEF_SIGNED_STR, buffer); DEADBEEF_SIGNED_STR, buffer);
status = TC_FAIL; status = TC_FAIL;
} }
/*******************/ /*******************/
len = sprintf(buffer, "%o", DEADBEEF); len = sprintf(buffer, "%o", DEADBEEF);
if (len != strlen(DEADBEEF_OCTAL_STR)) { if (len != strlen(DEADBEEF_OCTAL_STR)) {
TC_ERROR("sprintf(%%o). Expected %d bytes written, not %d\n", TC_ERROR("sprintf(%%o). Expected %d bytes written, not %d\n",
strlen(DEADBEEF_OCTAL_STR), len); strlen(DEADBEEF_OCTAL_STR), len);
status = TC_FAIL; status = TC_FAIL;
} }
if (strcmp(buffer, DEADBEEF_OCTAL_STR) != 0) { if (strcmp(buffer, DEADBEEF_OCTAL_STR) != 0) {
TC_ERROR("sprintf(%%o). Expected '%s', got '%s'\n", TC_ERROR("sprintf(%%o). Expected '%s', got '%s'\n",
DEADBEEF_OCTAL_STR, buffer); DEADBEEF_OCTAL_STR, buffer);
status = TC_FAIL; status = TC_FAIL;
} }
/*******************/ /*******************/
len = sprintf(buffer, "%#o", DEADBEEF); len = sprintf(buffer, "%#o", DEADBEEF);
if (len != strlen(DEADBEEF_OCTAL_ALT_STR)) { if (len != strlen(DEADBEEF_OCTAL_ALT_STR)) {
TC_ERROR("sprintf(%%#o). Expected %d bytes written, not %d\n", TC_ERROR("sprintf(%%#o). Expected %d bytes written, not %d\n",
strlen(DEADBEEF_OCTAL_ALT_STR), len); strlen(DEADBEEF_OCTAL_ALT_STR), len);
status = TC_FAIL; status = TC_FAIL;
} }
if (strcmp(buffer, DEADBEEF_OCTAL_ALT_STR) != 0) { if (strcmp(buffer, DEADBEEF_OCTAL_ALT_STR) != 0) {
TC_ERROR("sprintf(%%#o). Expected '%s', got '%s'\n", TC_ERROR("sprintf(%%#o). Expected '%s', got '%s'\n",
DEADBEEF_OCTAL_ALT_STR, buffer); DEADBEEF_OCTAL_ALT_STR, buffer);
status = TC_FAIL; status = TC_FAIL;
} }
/*******************/ /*******************/
len = sprintf(buffer, "%#x", DEADBEEF); len = sprintf(buffer, "%#x", DEADBEEF);
if (len != strlen(DEADBEEF_LHEX_ALT_STR)) { if (len != strlen(DEADBEEF_LHEX_ALT_STR)) {
TC_ERROR("sprintf(%%#x). Expected %d bytes written, not %d\n", TC_ERROR("sprintf(%%#x). Expected %d bytes written, not %d\n",
strlen(DEADBEEF_LHEX_ALT_STR), len); strlen(DEADBEEF_LHEX_ALT_STR), len);
status = TC_FAIL; status = TC_FAIL;
} }
if (strcmp(buffer, DEADBEEF_LHEX_ALT_STR) != 0) { if (strcmp(buffer, DEADBEEF_LHEX_ALT_STR) != 0) {
TC_ERROR("sprintf(%%#x). Expected '%s', got '%s'\n", TC_ERROR("sprintf(%%#x). Expected '%s', got '%s'\n",
DEADBEEF_LHEX_ALT_STR, buffer); DEADBEEF_LHEX_ALT_STR, buffer);
status = TC_FAIL; status = TC_FAIL;
} }
/*******************/ /*******************/
len = sprintf(buffer, "%#X", DEADBEEF); len = sprintf(buffer, "%#X", DEADBEEF);
if (len != strlen(DEADBEEF_UHEX_ALT_STR)) { if (len != strlen(DEADBEEF_UHEX_ALT_STR)) {
TC_ERROR("sprintf(%%#X). Expected %d bytes written, not %d\n", TC_ERROR("sprintf(%%#X). Expected %d bytes written, not %d\n",
strlen(DEADBEEF_UHEX_ALT_STR), len); strlen(DEADBEEF_UHEX_ALT_STR), len);
status = TC_FAIL; status = TC_FAIL;
} }
if (strcmp(buffer, DEADBEEF_UHEX_ALT_STR) != 0) { if (strcmp(buffer, DEADBEEF_UHEX_ALT_STR) != 0) {
TC_ERROR("sprintf(%%#X). Expected '%s', got '%s'\n", TC_ERROR("sprintf(%%#X). Expected '%s', got '%s'\n",
DEADBEEF_UHEX_ALT_STR, buffer); DEADBEEF_UHEX_ALT_STR, buffer);
status = TC_FAIL; status = TC_FAIL;
} }
/*******************/ /*******************/
len = sprintf(buffer, "%+d", 1); len = sprintf(buffer, "%+d", 1);
if (len != 2) { if (len != 2) {
TC_ERROR("sprintf(%%+d). Expected %d bytes written, not %d\n", TC_ERROR("sprintf(%%+d). Expected %d bytes written, not %d\n",
2, len); 2, len);
status = TC_FAIL; status = TC_FAIL;
} }
if (strcmp(buffer, "+1") != 0) { if (strcmp(buffer, "+1") != 0) {
TC_ERROR("sprintf(%%+d). Expected '+1', got '%s'\n", buffer); TC_ERROR("sprintf(%%+d). Expected '+1', got '%s'\n", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
return status; return status;
} }
@ -691,31 +690,31 @@ int sprintfStringTest(void)
if (strcmp(buffer, "%") != 0) { if (strcmp(buffer, "%") != 0) {
TC_ERROR("sprintf(%%). Expected '%%', got '%s'\n", buffer); TC_ERROR("sprintf(%%). Expected '%%', got '%s'\n", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
sprintf(buffer, "%c", 't'); sprintf(buffer, "%c", 't');
if (strcmp(buffer, "t") != 0) { if (strcmp(buffer, "t") != 0) {
TC_ERROR("sprintf(%%c). Expected 't', got '%s'\n", buffer); TC_ERROR("sprintf(%%c). Expected 't', got '%s'\n", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
sprintf(buffer, "%s", "short string"); sprintf(buffer, "%s", "short string");
if (strcmp(buffer, "short string") != 0) { if (strcmp(buffer, "short string") != 0) {
TC_ERROR("sprintf(%%s). Expected 'short string', got '%s'\n", buffer); TC_ERROR("sprintf(%%s). Expected 'short string', got '%s'\n", buffer);
status = TC_FAIL; status = TC_FAIL;
} }
len = sprintf(buffer, "%s", REALLY_LONG_STRING); len = sprintf(buffer, "%s", REALLY_LONG_STRING);
if (len != PRINTF_MAX_STRING_LENGTH) { if (len != PRINTF_MAX_STRING_LENGTH) {
TC_ERROR("Internals changed. Max string length no longer %d\n", TC_ERROR("Internals changed. Max string length no longer %d\n",
PRINTF_MAX_STRING_LENGTH); PRINTF_MAX_STRING_LENGTH);
status = TC_FAIL; status = TC_FAIL;
} }
if (strncmp(buffer, REALLY_LONG_STRING, PRINTF_MAX_STRING_LENGTH) != 0) { if (strncmp(buffer, REALLY_LONG_STRING, PRINTF_MAX_STRING_LENGTH) != 0) {
TC_ERROR("First %d characters of REALLY_LONG_STRING not printed!\n", TC_ERROR("First %d characters of REALLY_LONG_STRING not printed!\n",
PRINTF_MAX_STRING_LENGTH); PRINTF_MAX_STRING_LENGTH);
status = TC_FAIL; status = TC_FAIL;
} }
return status; return status;
} }
@ -738,38 +737,38 @@ void RegressionTask(void)
TC_PRINT("Testing sprintf() with integers ....\n"); TC_PRINT("Testing sprintf() with integers ....\n");
if (sprintfIntegerTest() != TC_PASS) { if (sprintfIntegerTest() != TC_PASS) {
status = TC_FAIL; status = TC_FAIL;
} }
TC_PRINT("Testing snprintf() ....\n"); TC_PRINT("Testing snprintf() ....\n");
if (snprintfTest() != TC_PASS) { if (snprintfTest() != TC_PASS) {
status = TC_FAIL; status = TC_FAIL;
} }
TC_PRINT("Testing vsprintf() ....\n"); TC_PRINT("Testing vsprintf() ....\n");
if (vsprintfTest() != TC_PASS) { if (vsprintfTest() != TC_PASS) {
status = TC_FAIL; status = TC_FAIL;
} }
TC_PRINT("Testing vsnprintf() ....\n"); TC_PRINT("Testing vsnprintf() ....\n");
if (vsnprintfTest() != TC_PASS) { if (vsnprintfTest() != TC_PASS) {
status = TC_FAIL; status = TC_FAIL;
} }
TC_PRINT("Testing sprintf() with strings ....\n"); TC_PRINT("Testing sprintf() with strings ....\n");
if (sprintfStringTest() != TC_PASS) { if (sprintfStringTest() != TC_PASS) {
status = TC_FAIL; status = TC_FAIL;
} }
TC_PRINT("Testing sprintf() with misc options ....\n"); TC_PRINT("Testing sprintf() with misc options ....\n");
if (sprintfMiscTest() != TC_PASS) { if (sprintfMiscTest() != TC_PASS) {
status = TC_FAIL; status = TC_FAIL;
} }
#ifdef CONFIG_FLOAT #ifdef CONFIG_FLOAT
TC_PRINT("Testing sprintf() with doubles ....\n"); TC_PRINT("Testing sprintf() with doubles ....\n");
if (sprintfDoubleTest() != TC_PASS) { if (sprintfDoubleTest() != TC_PASS) {
status = TC_FAIL; status = TC_FAIL;
} }
#endif /* CONFIG_FLOAT */ #endif /* CONFIG_FLOAT */
TC_END_RESULT(status); TC_END_RESULT(status);

View file

@ -85,10 +85,10 @@ void check_input(const char *name, const char *input);
void printLoop(const char *name) void printLoop(const char *name)
{ {
while (count < 6) { while (count < 6) {
/* A short input string to check_input. It will pass. */ /* A short input string to check_input. It will pass. */
check_input(name, "Stack ok"); check_input(name, "Stack ok");
count++; count++;
} }
} }
/******************************************************************************* /*******************************************************************************
@ -109,7 +109,7 @@ void printLoop(const char *name)
void check_input(const char *name, const char *input) void check_input(const char *name, const char *input)
{ {
/* Stack will overflow when input is more than 16 characters */ /* Stack will overflow when input is more than 16 characters */
char buf[16]; char buf[16];
strcpy(buf, input); strcpy(buf, input);
@ -135,12 +135,11 @@ void fiber1(void)
#endif /* ! CONFIG_MICROKERNEL */ #endif /* ! CONFIG_MICROKERNEL */
{ {
TC_PRINT("Starts %s\n", __func__); TC_PRINT("Starts %s\n", __func__);
check_input(__func__, check_input(__func__, "Input string is too long and stack overflowed!\n");
"Input string is too long and stack overflowed!\n"); /*
/* * Expect this task to terminate due to stack check fail and will not
* Expect this task to terminate due to stack check fail and will not * execute pass here.
* execute pass here. */
*/
printLoop(__func__); printLoop(__func__);
tcRC = TC_FAIL; tcRC = TC_FAIL;
@ -168,17 +167,17 @@ void main(void)
TC_PRINT("Starts %s\n", __func__); TC_PRINT("Starts %s\n", __func__);
#ifdef CONFIG_MICROKERNEL #ifdef CONFIG_MICROKERNEL
/* Start task */ /* Start task */
task_start(ALTERNATETASK); /* refer to prj.vpf file */ task_start(ALTERNATETASK); /* refer to prj.vpf file */
#else #else
/* Start fiber */ /* Start fiber */
task_fiber_start(&fiberStack[0], STACKSIZE, task_fiber_start(&fiberStack[0], STACKSIZE,
(nano_fiber_entry_t) fiber1, 0, 0, 7, 0); (nano_fiber_entry_t) fiber1, 0, 0, 7, 0);
#endif /* ! CONFIG_MICROKERNEL */ #endif /* ! CONFIG_MICROKERNEL */
if (tcRC == TC_FAIL) { if (tcRC == TC_FAIL) {
goto errorExit; goto errorExit;
} }
printLoop(__func__); printLoop(__func__);

View file

@ -137,44 +137,44 @@ int nanoIdtStubTest(void)
IDT_ENTRY *pIdtEntry; IDT_ENTRY *pIdtEntry;
uint16_t offset; uint16_t offset;
/* Check for the interrupt stub */ /* Check for the interrupt stub */
pIdtEntry = (IDT_ENTRY *) (_idt_base_address + (TEST_SOFT_INT << 3)); pIdtEntry = (IDT_ENTRY *) (_idt_base_address + (TEST_SOFT_INT << 3));
offset = (uint16_t)((uint32_t)(&nanoIntStub) & 0xFFFF); offset = (uint16_t)((uint32_t)(&nanoIntStub) & 0xFFFF);
if (pIdtEntry->lowOffset != offset) { if (pIdtEntry->lowOffset != offset) {
TC_ERROR("Failed to find low offset of nanoIntStub \ TC_ERROR("Failed to find low offset of nanoIntStub "
(0x%x) at vector %d\n", (uint32_t)offset, TEST_SOFT_INT); "(0x%x) at vector %d\n", (uint32_t)offset, TEST_SOFT_INT);
return TC_FAIL; return TC_FAIL;
} }
offset = (uint16_t)((uint32_t)(&nanoIntStub) >> 16); offset = (uint16_t)((uint32_t)(&nanoIntStub) >> 16);
if (pIdtEntry->hiOffset != offset) { if (pIdtEntry->hiOffset != offset) {
TC_ERROR("Failed to find high offset of nanoIntStub \ TC_ERROR("Failed to find high offset of nanoIntStub "
(0x%x) at vector %d\n", (uint32_t)offset, TEST_SOFT_INT); "(0x%x) at vector %d\n", (uint32_t)offset, TEST_SOFT_INT);
return TC_FAIL; return TC_FAIL;
} }
/* Check for the exception stub */ /* Check for the exception stub */
pIdtEntry = (IDT_ENTRY *) (_idt_base_address + (IV_DIVIDE_ERROR << 3)); pIdtEntry = (IDT_ENTRY *) (_idt_base_address + (IV_DIVIDE_ERROR << 3));
offset = (uint16_t)((uint32_t)(&exc_divide_error_handlerStub) & 0xFFFF); offset = (uint16_t)((uint32_t)(&exc_divide_error_handlerStub) & 0xFFFF);
if (pIdtEntry->lowOffset != offset) { if (pIdtEntry->lowOffset != offset) {
TC_ERROR("Failed to find low offset of exc stub \ TC_ERROR("Failed to find low offset of exc stub "
(0x%x) at vector %d\n", (uint32_t)offset, IV_DIVIDE_ERROR); "(0x%x) at vector %d\n", (uint32_t)offset, IV_DIVIDE_ERROR);
return TC_FAIL; return TC_FAIL;
} }
offset = (uint16_t)((uint32_t)(&exc_divide_error_handlerStub) >> 16); offset = (uint16_t)((uint32_t)(&exc_divide_error_handlerStub) >> 16);
if (pIdtEntry->hiOffset != offset) { if (pIdtEntry->hiOffset != offset) {
TC_ERROR("Failed to find high offset of exc stub \ TC_ERROR("Failed to find high offset of exc stub "
(0x%x) at vector %d\n", (uint32_t)offset, IV_DIVIDE_ERROR); "(0x%x) at vector %d\n", (uint32_t)offset, IV_DIVIDE_ERROR);
return TC_FAIL; return TC_FAIL;
} }
/* /*
* If the other fields are wrong, the system will crash when the exception * If the other fields are wrong, the system will crash when the exception
* and software interrupt are triggered so we don't check them. * and software interrupt are triggered so we don't check them.
*/ */
return TC_PASS; return TC_PASS;
} }
@ -200,7 +200,7 @@ static void idtSpurFiber(int a1, int a2)
_trigger_spurHandler(); _trigger_spurHandler();
/* Shouldn't get here */ /* Shouldn't get here */
spurHandlerAbortedContext = 0; spurHandlerAbortedContext = 0;
} }
@ -230,59 +230,59 @@ void main(void)
rv = nanoIdtStubTest(); rv = nanoIdtStubTest();
if (rv != TC_PASS) { if (rv != TC_PASS) {
goto doneTests; goto doneTests;
} }
TC_PRINT("Testing to see interrupt handler executes properly\n"); TC_PRINT("Testing to see interrupt handler executes properly\n");
_trigger_isrHandler(); _trigger_isrHandler();
if (intHandlerExecuted == 0) { if (intHandlerExecuted == 0) {
TC_ERROR("Interrupt handler did not execute\n"); TC_ERROR("Interrupt handler did not execute\n");
rv = TC_FAIL; rv = TC_FAIL;
goto doneTests; goto doneTests;
} else if (intHandlerExecuted != 1) { } else if (intHandlerExecuted != 1) {
TC_ERROR("Interrupt handler executed more than once! (%d)\n", TC_ERROR("Interrupt handler executed more than once! (%d)\n",
intHandlerExecuted); intHandlerExecuted);
rv = TC_FAIL; rv = TC_FAIL;
goto doneTests; goto doneTests;
} }
TC_PRINT("Testing to see exception handler executes properly\n"); TC_PRINT("Testing to see exception handler executes properly\n");
/* /*
* Use excHandlerExecuted instead of 0 to prevent the compiler issuing a * Use excHandlerExecuted instead of 0 to prevent the compiler issuing a
* 'divide by zero' warning. * 'divide by zero' warning.
*/ */
error = error / excHandlerExecuted; error = error / excHandlerExecuted;
if (excHandlerExecuted == 0) { if (excHandlerExecuted == 0) {
TC_ERROR("Exception handler did not execute\n"); TC_ERROR("Exception handler did not execute\n");
rv = TC_FAIL; rv = TC_FAIL;
goto doneTests; goto doneTests;
} }
else if (excHandlerExecuted != 1) { else if (excHandlerExecuted != 1) {
TC_ERROR("Exception handler executed more than once! (%d)\n", TC_ERROR("Exception handler executed more than once! (%d)\n",
excHandlerExecuted); excHandlerExecuted);
rv = TC_FAIL; rv = TC_FAIL;
goto doneTests; goto doneTests;
} }
/* /*
* Start fiber/task to trigger the spurious interrupt handler * Start fiber/task to trigger the spurious interrupt handler
*/ */
TC_PRINT("Testing to see spurious handler executes properly\n"); TC_PRINT("Testing to see spurious handler executes properly\n");
#ifdef CONFIG_MICROKERNEL #ifdef CONFIG_MICROKERNEL
task_start(tSpurTask); task_start(tSpurTask);
#else #else
task_fiber_start(fiberStack, sizeof(fiberStack), idtSpurFiber, 0, 0, 5, 0); task_fiber_start(fiberStack, sizeof(fiberStack), idtSpurFiber, 0, 0, 5, 0);
#endif #endif
/* /*
* The fiber/task should not run past where the spurious interrupt is * The fiber/task should not run past where the spurious interrupt is
* generated. Therefore spurHandlerAbortedContext should remain at 1. * generated. Therefore spurHandlerAbortedContext should remain at 1.
*/ */
if (spurHandlerAbortedContext == 0) { if (spurHandlerAbortedContext == 0) {
TC_ERROR("Spurious handler did not execute as expected\n"); TC_ERROR("Spurious handler did not execute as expected\n");
rv = TC_FAIL; rv = TC_FAIL;
goto doneTests; goto doneTests;
} }
doneTests: doneTests:

View file

@ -65,7 +65,7 @@ This module tests the following task APIs:
typedef struct { typedef struct {
int cmd; int cmd;
int data; int data;
} ISR_INFO; } ISR_INFO;
/* locals */ /* locals */
@ -91,14 +91,14 @@ void isr_task_command_handler(void *data)
int value = -1; int value = -1;
switch (pInfo->cmd) { switch (pInfo->cmd) {
case CMD_TASKID: case CMD_TASKID:
value = isr_task_id_get(); value = isr_task_id_get();
break; break;
case CMD_PRIORITY: case CMD_PRIORITY:
value = isr_task_priority_get(); value = isr_task_priority_get();
break; break;
} }
pInfo->data = value; pInfo->data = value;
} }
@ -116,17 +116,17 @@ int isrAPIsTest(int taskId, int taskPrio)
_trigger_isrTaskCommand(); _trigger_isrTaskCommand();
if (isrInfo.data != taskId) { if (isrInfo.data != taskId) {
TC_ERROR("isr_task_id_get() returned %d, not %d\n", TC_ERROR("isr_task_id_get() returned %d, not %d\n",
isrInfo.data, taskId); isrInfo.data, taskId);
return TC_FAIL; return TC_FAIL;
} }
isrInfo.cmd = CMD_PRIORITY; isrInfo.cmd = CMD_PRIORITY;
_trigger_isrTaskCommand(); _trigger_isrTaskCommand();
if (isrInfo.data != taskPrio) { if (isrInfo.data != taskPrio) {
TC_ERROR("isr_task_priority_get() returned %d, not %d\n", TC_ERROR("isr_task_priority_get() returned %d, not %d\n",
isrInfo.data, taskPrio); isrInfo.data, taskPrio);
return TC_FAIL; return TC_FAIL;
} }
return TC_PASS; return TC_PASS;
} }
@ -145,16 +145,16 @@ int taskMacrosTest(int taskId, int taskPrio)
value = task_id_get(); value = task_id_get();
if (value != taskId) { if (value != taskId) {
TC_ERROR("task_id_get() returned 0x%x, not 0x%x\n", TC_ERROR("task_id_get() returned 0x%x, not 0x%x\n",
value, taskId); value, taskId);
return TC_FAIL; return TC_FAIL;
} }
value = task_priority_get(); value = task_priority_get();
if (value != taskPrio) { if (value != taskPrio) {
TC_ERROR("task_priority_get() returned %d, not %d\n", TC_ERROR("task_priority_get() returned %d, not %d\n",
value, taskPrio); value, taskPrio);
return TC_FAIL; return TC_FAIL;
} }
return TC_PASS; return TC_PASS;
} }
@ -211,65 +211,65 @@ int taskSetPrioTest(void)
{ {
int rv; int rv;
/* Lower the priority of the current task (RegressionTask) */ /* Lower the priority of the current task (RegressionTask) */
task_priority_set(RT_TASKID, RT_PRIO + 5); task_priority_set(RT_TASKID, RT_PRIO + 5);
rv = task_priority_get(); rv = task_priority_get();
if (rv != RT_PRIO + 5) { if (rv != RT_PRIO + 5) {
TC_ERROR("Expected priority to be changed to %d, not %d\n", TC_ERROR("Expected priority to be changed to %d, not %d\n",
RT_PRIO + 5, rv); RT_PRIO + 5, rv);
return TC_FAIL; return TC_FAIL;
} }
/* Raise the priority of the current task (RegressionTask) */ /* Raise the priority of the current task (RegressionTask) */
task_priority_set(RT_TASKID, RT_PRIO - 5); task_priority_set(RT_TASKID, RT_PRIO - 5);
rv = task_priority_get(); rv = task_priority_get();
if (rv != RT_PRIO - 5) { if (rv != RT_PRIO - 5) {
TC_ERROR("Expected priority to be changed to %d, not %d\n", TC_ERROR("Expected priority to be changed to %d, not %d\n",
RT_PRIO - 5, rv); RT_PRIO - 5, rv);
return TC_FAIL; return TC_FAIL;
} }
/* Restore the priority of the current task (RegressionTask) */ /* Restore the priority of the current task (RegressionTask) */
task_priority_set(RT_TASKID, RT_PRIO); task_priority_set(RT_TASKID, RT_PRIO);
rv = task_priority_get(); rv = task_priority_get();
if (rv != RT_PRIO) { if (rv != RT_PRIO) {
TC_ERROR("Expected priority to be changed to %d, not %d\n", TC_ERROR("Expected priority to be changed to %d, not %d\n",
RT_PRIO, rv); RT_PRIO, rv);
return TC_FAIL; return TC_FAIL;
} }
/* Lower the priority of the helper task (HelperTask) */ /* Lower the priority of the helper task (HelperTask) */
task_priority_set(HT_TASKID, HT_PRIO + 5); task_priority_set(HT_TASKID, HT_PRIO + 5);
task_sem_give(HT_SEM); task_sem_give(HT_SEM);
task_sem_take_wait(RT_SEM); task_sem_take_wait(RT_SEM);
if (helperData != HT_PRIO + 5) { if (helperData != HT_PRIO + 5) {
TC_ERROR("Expected priority to be changed to %d, not %d\n", TC_ERROR("Expected priority to be changed to %d, not %d\n",
HT_PRIO + 5, helperData); HT_PRIO + 5, helperData);
return TC_FAIL; return TC_FAIL;
} }
/* Raise the priority of the helper task (HelperTask) */ /* Raise the priority of the helper task (HelperTask) */
task_priority_set(HT_TASKID, HT_PRIO - 5); task_priority_set(HT_TASKID, HT_PRIO - 5);
task_sem_give(HT_SEM); task_sem_give(HT_SEM);
task_sem_take_wait(RT_SEM); task_sem_take_wait(RT_SEM);
if (helperData != HT_PRIO - 5) { if (helperData != HT_PRIO - 5) {
TC_ERROR("Expected priority to be changed to %d, not %d\n", TC_ERROR("Expected priority to be changed to %d, not %d\n",
HT_PRIO - 5, helperData); HT_PRIO - 5, helperData);
return TC_FAIL; return TC_FAIL;
} }
/* Restore the priority of the helper task (HelperTask) */ /* Restore the priority of the helper task (HelperTask) */
task_priority_set(HT_TASKID, HT_PRIO); task_priority_set(HT_TASKID, HT_PRIO);
task_sem_give(HT_SEM); task_sem_give(HT_SEM);
task_sem_take_wait(RT_SEM); task_sem_take_wait(RT_SEM);
if (helperData != HT_PRIO) { if (helperData != HT_PRIO) {
TC_ERROR("Expected priority to be changed to %d, not %d\n", TC_ERROR("Expected priority to be changed to %d, not %d\n",
HT_PRIO, helperData); HT_PRIO, helperData);
return TC_FAIL; return TC_FAIL;
} }
return TC_PASS; return TC_PASS;
} }
@ -289,7 +289,7 @@ void helperTaskSleepTest(void)
firstTick = task_tick_get_32(); firstTick = task_tick_get_32();
while (mainTaskNotReady) { while (mainTaskNotReady) {
} }
helperData = task_tick_get_32() - firstTick; helperData = task_tick_get_32() - firstTick;
task_sem_give(RT_SEM); task_sem_give(RT_SEM);
@ -308,7 +308,7 @@ int taskSleepTest(void)
tick = task_tick_get_32(); /* Busy wait to align */ tick = task_tick_get_32(); /* Busy wait to align */
while (tick == task_tick_get_32()) { /* to tick boundary */ while (tick == task_tick_get_32()) { /* to tick boundary */
} }
task_sem_give(HT_SEM); task_sem_give(HT_SEM);
@ -319,9 +319,9 @@ int taskSleepTest(void)
if (helperData != SLEEP_TIME) { if (helperData != SLEEP_TIME) {
TC_ERROR("task_sleep() slept for %d ticks, not %d\n", TC_ERROR("task_sleep() slept for %d ticks, not %d\n",
helperData, SLEEP_TIME); helperData, SLEEP_TIME);
return TC_FAIL; return TC_FAIL;
} }
return TC_PASS; return TC_PASS;
} }
@ -341,7 +341,7 @@ void helperTaskYieldTest(void)
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
helperData++; helperData++;
task_yield(); task_yield();
} }
task_sem_give(RT_SEM); task_sem_give(RT_SEM);
} }
@ -360,7 +360,7 @@ int taskYieldTest(void)
helperData = 0; helperData = 0;
/* 1st raise the priority of the helper task */ /* 1st raise the priority of the helper task */
task_priority_set(HT_TASKID, RT_PRIO); task_priority_set(HT_TASKID, RT_PRIO);
task_sem_give(HT_SEM); task_sem_give(HT_SEM);
@ -369,16 +369,16 @@ int taskYieldTest(void)
task_yield(); task_yield();
if (helperData == prevHelperData) { if (helperData == prevHelperData) {
TC_ERROR("Iter %d. helperData did not change (%d) \n", TC_ERROR("Iter %d. helperData did not change (%d) \n",
i + 1, helperData); i + 1, helperData);
return TC_FAIL; return TC_FAIL;
}
} }
}
/* Restore helper task priority */ /* Restore helper task priority */
task_priority_set(HT_TASKID, HT_PRIO); task_priority_set(HT_TASKID, HT_PRIO);
/* Ensure that the helper task finishes */ /* Ensure that the helper task finishes */
task_sem_take_wait(RT_SEM); task_sem_take_wait(RT_SEM);
return TC_PASS; return TC_PASS;
@ -424,7 +424,7 @@ int taskSuspendTest(void)
if (prevHelperData != helperData) { if (prevHelperData != helperData) {
TC_ERROR("Helper task did not suspend!\n"); TC_ERROR("Helper task did not suspend!\n");
return TC_FAIL; return TC_FAIL;
} }
task_resume(HT_TASKID); task_resume(HT_TASKID);
task_sleep(SLEEP_TIME); task_sleep(SLEEP_TIME);
@ -432,7 +432,7 @@ int taskSuspendTest(void)
if (prevHelperData == helperData) { if (prevHelperData == helperData) {
TC_ERROR("Helper task did not resume!\n"); TC_ERROR("Helper task did not resume!\n");
return TC_FAIL; return TC_FAIL;
} }
task_sem_give(HT_SEM); task_sem_give(HT_SEM);
return TC_PASS; return TC_PASS;
@ -454,7 +454,7 @@ void HelperTask(void)
if (rv != TC_PASS) { if (rv != TC_PASS) {
tcRC = TC_FAIL; tcRC = TC_FAIL;
return; return;
} }
task_sem_give(RT_SEM); task_sem_give(RT_SEM);
task_sem_take_wait(HT_SEM); task_sem_take_wait(HT_SEM);
@ -462,7 +462,7 @@ void HelperTask(void)
if (rv != TC_PASS) { if (rv != TC_PASS) {
tcRC = TC_FAIL; tcRC = TC_FAIL;
return; return;
} }
task_sem_give(RT_SEM); task_sem_give(RT_SEM);
helperTaskSetPrioTest(); helperTaskSetPrioTest();
@ -496,7 +496,7 @@ void RegressionTask(void)
if (rv != TC_PASS) { if (rv != TC_PASS) {
tcRC = TC_FAIL; tcRC = TC_FAIL;
goto errorReturn; goto errorReturn;
} }
task_sem_give(HT_SEM); task_sem_give(HT_SEM);
task_sem_take_wait(RT_SEM); task_sem_take_wait(RT_SEM);
@ -506,7 +506,7 @@ void RegressionTask(void)
if (rv != TC_PASS) { if (rv != TC_PASS) {
tcRC = TC_FAIL; tcRC = TC_FAIL;
goto errorReturn; goto errorReturn;
} }
task_sem_give(HT_SEM); task_sem_give(HT_SEM);
task_sem_take_wait(RT_SEM); task_sem_take_wait(RT_SEM);
@ -515,25 +515,25 @@ void RegressionTask(void)
if (taskSetPrioTest() != TC_PASS) { if (taskSetPrioTest() != TC_PASS) {
tcRC = TC_FAIL; tcRC = TC_FAIL;
goto errorReturn; goto errorReturn;
} }
TC_PRINT("Testing task_sleep()\n"); TC_PRINT("Testing task_sleep()\n");
if (taskSleepTest() != TC_PASS) { if (taskSleepTest() != TC_PASS) {
tcRC = TC_FAIL; tcRC = TC_FAIL;
goto errorReturn; goto errorReturn;
} }
TC_PRINT("Testing task_yield()\n"); TC_PRINT("Testing task_yield()\n");
if (taskYieldTest() != TC_PASS) { if (taskYieldTest() != TC_PASS) {
tcRC = TC_FAIL; tcRC = TC_FAIL;
goto errorReturn; goto errorReturn;
} }
TC_PRINT("Testing task_suspend() and task_resume()\n"); TC_PRINT("Testing task_suspend() and task_resume()\n");
if (taskSuspendTest() != TC_PASS) { if (taskSuspendTest() != TC_PASS) {
tcRC = TC_FAIL; tcRC = TC_FAIL;
goto errorReturn; goto errorReturn;
} }
errorReturn: errorReturn:
TC_END_RESULT(tcRC); TC_END_RESULT(tcRC);

View file

@ -64,10 +64,10 @@ static ksem_t rdySem = SEM_RDY;
*/ */
void taskAMain(void) void taskAMain(void)
{ {
extern int taskA(ksem_t semRdy); extern int taskA(ksem_t semRdy);
task_sem_give(resultSems[taskA(rdySem)]); task_sem_give(resultSems[taskA(rdySem)]);
} }
/******************************************************************************* /*******************************************************************************
* *
@ -80,10 +80,10 @@ void taskAMain(void)
*/ */
void taskBMain(void) void taskBMain(void)
{ {
extern int taskB(ksem_t semRdy); extern int taskB(ksem_t semRdy);
task_sem_give(resultSems[taskB(rdySem)]); task_sem_give(resultSems[taskB(rdySem)]);
} }
/******************************************************************************* /*******************************************************************************
* *
@ -96,29 +96,30 @@ void taskBMain(void)
* RETURNS: N/A * RETURNS: N/A
*/ */
void registerWait(void) void registerWait(void)
{ {
extern void raiseInt(uint8_t id); extern void raiseInt(uint8_t id);
int tasksDone; int tasksDone;
int irq_obj; int irq_obj;
/* Wait for the 2 tasks to finish registering their IRQ objects*/ /* Wait for the 2 tasks to finish registering their IRQ objects*/
for (tasksDone = 0; tasksDone < NUM_TEST_TASKS - 1; tasksDone++) { for (tasksDone = 0; tasksDone < NUM_TEST_TASKS - 1; tasksDone++) {
if (task_sem_take_wait_timeout(SEM_RDY, TIMEOUT) != RC_OK) { if (task_sem_take_wait_timeout(SEM_RDY, TIMEOUT) != RC_OK) {
TC_ERROR("Monitor task timed out\n"); TC_ERROR("Monitor task timed out\n");
task_sem_give(resultSems[TC_FAIL]); task_sem_give(resultSems[TC_FAIL]);
return; return;
}
} }
}
TC_PRINT("Generating interrupts for all allocated IRQ objects...\n"); TC_PRINT("Generating interrupts for all allocated IRQ objects...\n");
for (irq_obj = 0; irq_obj < NUM_TASK_IRQS; irq_obj++) { for (irq_obj = 0; irq_obj < NUM_TASK_IRQS; irq_obj++) {
if (task_irq_object[irq_obj].irq != INVALID_VECTOR) if (task_irq_object[irq_obj].irq != INVALID_VECTOR) {
raiseInt((uint8_t)task_irq_object[irq_obj].vector); raiseInt((uint8_t)task_irq_object[irq_obj].vector);
} }
}
task_sem_give(resultSems[TC_PASS]); task_sem_give(resultSems[TC_PASS]);
} }
/******************************************************************************* /*******************************************************************************
* *
@ -131,7 +132,7 @@ void registerWait(void)
*/ */
void MonitorTaskEntry(void) void MonitorTaskEntry(void)
{ {
extern struct task_irq_info task_irq_object[NUM_TASK_IRQS]; extern struct task_irq_info task_irq_object[NUM_TASK_IRQS];
ksem_t result; ksem_t result;
int tasksDone; int tasksDone;
@ -139,24 +140,24 @@ void MonitorTaskEntry(void)
PRINT_DATA("Starting task level interrupt handling tests\n"); PRINT_DATA("Starting task level interrupt handling tests\n");
PRINT_LINE; PRINT_LINE;
/* /*
* the various test tasks start executing automatically; * the various test tasks start executing automatically;
* wait for all tasks to complete or a failure to occur, * wait for all tasks to complete or a failure to occur,
* then issue the appropriate test case summary message * then issue the appropriate test case summary message
*/ */
for (tasksDone = 0; tasksDone < NUM_TEST_TASKS; tasksDone++) { for (tasksDone = 0; tasksDone < NUM_TEST_TASKS; tasksDone++) {
result = task_sem_group_take_wait_timeout(resultSems, TIMEOUT); result = task_sem_group_take_wait_timeout(resultSems, TIMEOUT);
if (result != resultSems[TC_PASS]) { if (result != resultSems[TC_PASS]) {
if (result != resultSems[TC_FAIL]) { if (result != resultSems[TC_FAIL]) {
TC_ERROR("Monitor task timed out\n"); TC_ERROR("Monitor task timed out\n");
} }
TC_END_RESULT(TC_FAIL); TC_END_RESULT(TC_FAIL);
TC_END_REPORT(TC_FAIL); TC_END_REPORT(TC_FAIL);
return; return;
}
} }
}
TC_END_RESULT(TC_PASS); TC_END_RESULT(TC_PASS);
TC_END_REPORT(TC_PASS); TC_END_REPORT(TC_PASS);
} }

File diff suppressed because it is too large Load diff

View file

@ -77,63 +77,63 @@ exercises the task_irq_free() API.
*/ */
int taskA(ksem_t semRdy) int taskA(ksem_t semRdy)
{ {
if (task_irq_alloc(DEV1_ID, DEV1_IRQ, 1) == INVALID_VECTOR) { if (task_irq_alloc(DEV1_ID, DEV1_IRQ, 1) == INVALID_VECTOR) {
TC_ERROR("Not able to allocate IRQ object\n"); TC_ERROR("Not able to allocate IRQ object\n");
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT("IRQ object %d using IRQ%d allocated\n", DEV1_ID, DEV1_IRQ); TC_PRINT("IRQ object %d using IRQ%d allocated\n", DEV1_ID, DEV1_IRQ);
if (task_irq_alloc(DEV2_ID, DEV2_IRQ, 2) == INVALID_VECTOR) { if (task_irq_alloc(DEV2_ID, DEV2_IRQ, 2) == INVALID_VECTOR) {
TC_ERROR("Not able to allocate IRQ object\n"); TC_ERROR("Not able to allocate IRQ object\n");
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT("IRQ object %d using IRQ%d allocated\n\n", DEV2_ID, DEV2_IRQ); TC_PRINT("IRQ object %d using IRQ%d allocated\n\n", DEV2_ID, DEV2_IRQ);
/* Send semaphore to let loader know IRQ objects have been allocated */ /* Send semaphore to let loader know IRQ objects have been allocated */
task_sem_give(semRdy); task_sem_give(semRdy);
if (task_irq_test_wait(DEV1_ID) != RC_OK) { if (task_irq_test_wait(DEV1_ID) != RC_OK) {
TC_ERROR("Not able to test IRQ object event\n"); TC_ERROR("Not able to test IRQ object event\n");
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT("Received event for IRQ object %d\n", DEV1_ID); TC_PRINT("Received event for IRQ object %d\n", DEV1_ID);
task_irq_ack(DEV1_ID); task_irq_ack(DEV1_ID);
if (task_irq_test_wait(DEV2_ID) != RC_OK) { if (task_irq_test_wait(DEV2_ID) != RC_OK) {
TC_ERROR("Not able to test IRQ object event\n"); TC_ERROR("Not able to test IRQ object event\n");
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT("Received event for IRQ object %d\n", DEV2_ID); TC_PRINT("Received event for IRQ object %d\n", DEV2_ID);
task_irq_ack(DEV2_ID); task_irq_ack(DEV2_ID);
/* Wait for other task to receive its events */ /* Wait for other task to receive its events */
(void)task_sem_take_wait(semRdy); (void)task_sem_take_wait(semRdy);
TC_PRINT("\nAttempt to allocate an IRQ object that\n"); TC_PRINT("\nAttempt to allocate an IRQ object that\n");
TC_PRINT("is already allocated by another task...\n"); TC_PRINT("is already allocated by another task...\n");
if (task_irq_alloc(DEV4_ID, DEV4_IRQ, 1) != INVALID_VECTOR) { if (task_irq_alloc(DEV4_ID, DEV4_IRQ, 1) != INVALID_VECTOR) {
TC_ERROR("Error: Was able to allocate\n\n"); TC_ERROR("Error: Was able to allocate\n\n");
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT("Re-allocation of IRQ object %d prevented\n", DEV4_ID); TC_PRINT("Re-allocation of IRQ object %d prevented\n", DEV4_ID);
TC_PRINT("\nAttempt to allocate an IRQ that\n" TC_PRINT("\nAttempt to allocate an IRQ that\n"
"is already allocated by another task...\n"); "is already allocated by another task...\n");
if (task_irq_alloc(DEV5_ID, DEV4_IRQ, 1) != INVALID_VECTOR) { if (task_irq_alloc(DEV5_ID, DEV4_IRQ, 1) != INVALID_VECTOR) {
TC_ERROR("Error: Was able to allocate\n\n"); TC_ERROR("Error: Was able to allocate\n\n");
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT("Re-allocation of IRQ%d prevented\n\n", DEV4_IRQ); TC_PRINT("Re-allocation of IRQ%d prevented\n\n", DEV4_IRQ);
/* Signal other task that we are done processing */ /* Signal other task that we are done processing */
task_sem_give(semRdy); task_sem_give(semRdy);
return TC_PASS; return TC_PASS;
} }
/******************************************************************************* /*******************************************************************************
* *
@ -147,46 +147,46 @@ int taskA(ksem_t semRdy)
*/ */
int taskB(ksem_t semRdy) int taskB(ksem_t semRdy)
{ {
if (task_irq_alloc(DEV3_ID, DEV3_IRQ, 1) == INVALID_VECTOR) { if (task_irq_alloc(DEV3_ID, DEV3_IRQ, 1) == INVALID_VECTOR) {
TC_ERROR("Not able to allocate IRQ object\n"); TC_ERROR("Not able to allocate IRQ object\n");
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT("IRQ object %d using IRQ%d allocated\n", DEV3_ID, DEV3_IRQ); TC_PRINT("IRQ object %d using IRQ%d allocated\n", DEV3_ID, DEV3_IRQ);
if (task_irq_alloc(DEV4_ID, DEV4_IRQ, 1) == INVALID_VECTOR) { if (task_irq_alloc(DEV4_ID, DEV4_IRQ, 1) == INVALID_VECTOR) {
TC_ERROR("Not able to allocate IRQ object\n"); TC_ERROR("Not able to allocate IRQ object\n");
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT("IRQ object %d using IRQ%d allocated\n\n", DEV4_ID, DEV4_IRQ); TC_PRINT("IRQ object %d using IRQ%d allocated\n\n", DEV4_ID, DEV4_IRQ);
/* Send semaphore to let loader/main know objects have been allocated */ /* Send semaphore to let loader/main know objects have been allocated */
task_sem_give(semRdy); task_sem_give(semRdy);
if (task_irq_test_wait(DEV3_ID) != RC_OK) { if (task_irq_test_wait(DEV3_ID) != RC_OK) {
TC_ERROR("Not able to test IRQ object event\n"); TC_ERROR("Not able to test IRQ object event\n");
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT("Received event for IRQ object %d\n", DEV3_ID); TC_PRINT("Received event for IRQ object %d\n", DEV3_ID);
task_irq_ack(DEV3_ID); task_irq_ack(DEV3_ID);
if (task_irq_test_wait(DEV4_ID) != RC_OK) { if (task_irq_test_wait(DEV4_ID) != RC_OK) {
TC_ERROR("Not able to test IRQ object event\n"); TC_ERROR("Not able to test IRQ object event\n");
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT("Received event for IRQ object %d\n", DEV4_ID); TC_PRINT("Received event for IRQ object %d\n", DEV4_ID);
task_irq_ack(DEV4_ID); task_irq_ack(DEV4_ID);
/* Signal other task that we are done receiving events */ /* Signal other task that we are done receiving events */
task_sem_give(semRdy); task_sem_give(semRdy);
/* /*
* Wait for other task to finish processing. The signal just previously * Wait for other task to finish processing. The signal just previously
* sent will not be seen here as the other task is a higher priority and * sent will not be seen here as the other task is a higher priority and
* will thus consume the signal first. * will thus consume the signal first.
*/ */
(void)task_sem_take_wait(semRdy); (void)task_sem_take_wait(semRdy);
@ -195,4 +195,4 @@ int taskB(ksem_t semRdy)
TC_PRINT("IRQ object %d freed\n", DEV3_ID); TC_PRINT("IRQ object %d freed\n", DEV3_ID);
return TC_PASS; return TC_PASS;
} }

View file

@ -88,7 +88,7 @@ extern void _TimestampClose(void);
#endif #endif
void ticklessTestTask(void) void ticklessTestTask(void)
{ {
int32_t start_ticks; int32_t start_ticks;
int32_t end_ticks; int32_t end_ticks;
int32_t diff_ticks; int32_t diff_ticks;
@ -111,25 +111,25 @@ void ticklessTestTask(void)
printk("Calibrating TSC...\n"); printk("Calibrating TSC...\n");
#ifdef CONFIG_TICKLESS_IDLE #ifdef CONFIG_TICKLESS_IDLE
oldThreshold = _sys_idle_threshold_ticks; oldThreshold = _sys_idle_threshold_ticks;
/* make sure we do not enter tickless idle mode */ /* make sure we do not enter tickless idle mode */
_sys_idle_threshold_ticks = 0x7FFFFFFF; _sys_idle_threshold_ticks = 0x7FFFFFFF;
#endif #endif
/* initialize the timer, if necessary */ /* initialize the timer, if necessary */
_TIMESTAMP_OPEN(); _TIMESTAMP_OPEN();
for (i = 0; i < CAL_REPS; i++) { for (i = 0; i < CAL_REPS; i++) {
/* /*
* Do a single tick sleep to get us as close to a tick boundary * Do a single tick sleep to get us as close to a tick boundary
* as we can. * as we can.
*/ */
task_sleep(1); task_sleep(1);
start_ticks = task_tick_get_32(); start_ticks = task_tick_get_32();
start_tsc = _TIMESTAMP_READ(); start_tsc = _TIMESTAMP_READ();
task_sleep(SLEEP_TICKS); task_sleep(SLEEP_TICKS);
end_tsc = _TIMESTAMP_READ(); end_tsc = _TIMESTAMP_READ();
end_ticks = task_tick_get_32(); end_ticks = task_tick_get_32();
cal_tsc += end_tsc - start_tsc; cal_tsc += end_tsc - start_tsc;
} }
cal_tsc /= CAL_REPS; cal_tsc /= CAL_REPS;
@ -149,17 +149,17 @@ void ticklessTestTask(void)
printk("Going idle for %d ticks...\n", SLEEP_TICKS); printk("Going idle for %d ticks...\n", SLEEP_TICKS);
for (i = 0; i < CAL_REPS; i++) { for (i = 0; i < CAL_REPS; i++) {
/* /*
* Do a single tick sleep to get us as close to a tick boundary * Do a single tick sleep to get us as close to a tick boundary
* as we can. * as we can.
*/ */
task_sleep(1); task_sleep(1);
start_ticks = task_tick_get_32(); start_ticks = task_tick_get_32();
start_tsc = _TIMESTAMP_READ(); start_tsc = _TIMESTAMP_READ();
task_sleep(SLEEP_TICKS); task_sleep(SLEEP_TICKS);
end_tsc = _TIMESTAMP_READ(); end_tsc = _TIMESTAMP_READ();
end_ticks = task_tick_get_32(); end_ticks = task_tick_get_32();
diff_tsc += end_tsc - start_tsc; diff_tsc += end_tsc - start_tsc;
} }
diff_tsc /= CAL_REPS; diff_tsc /= CAL_REPS;
@ -180,25 +180,27 @@ void ticklessTestTask(void)
printk("Cal time stamp: 0x%x\n", cal_tsc); printk("Cal time stamp: 0x%x\n", cal_tsc);
#endif #endif
/* Calculate percentage difference between calibrated TSC diff and measured result */ /* Calculate percentage difference between calibrated TSC diff and measured result */
if (diff_tsc > cal_tsc) if (diff_tsc > cal_tsc) {
diff_per = (100 * (diff_tsc - cal_tsc)) / cal_tsc; diff_per = (100 * (diff_tsc - cal_tsc)) / cal_tsc;
else }
diff_per = (100 * (cal_tsc - diff_tsc)) / cal_tsc; else {
diff_per = (100 * (cal_tsc - diff_tsc)) / cal_tsc;
}
printk("variance in time stamp diff: %d percent\n", (int32_t)diff_per); printk("variance in time stamp diff: %d percent\n", (int32_t)diff_per);
if (diff_ticks != SLEEP_TICKS) { if (diff_ticks != SLEEP_TICKS) {
printk("* TEST FAILED. TICK COUNT INCORRECT *\n"); printk("* TEST FAILED. TICK COUNT INCORRECT *\n");
TC_END_REPORT(TC_FAIL); TC_END_REPORT(TC_FAIL);
} }
else { else {
TC_END_REPORT(TC_PASS); TC_END_REPORT(TC_PASS);
} }
/* release the timer, if necessary */ /* release the timer, if necessary */
_TIMESTAMP_CLOSE(); _TIMESTAMP_CLOSE();
while(1); while(1);
} }

View file

@ -82,14 +82,14 @@ BSP-specific timestamp support for the tickless idle test.
*/ */
void _TimestampOpen(void) void _TimestampOpen(void)
{ {
/* QEMU does not currently support the 32-bit timer modes of the GPTM */ /* QEMU does not currently support the 32-bit timer modes of the GPTM */
printk("WARNING! Timestamp is not supported for this target!\n"); printk("WARNING! Timestamp is not supported for this target!\n");
/* enable timer access */ /* enable timer access */
_CLKGATECTRL |= _CLKGATECTRL_TIMESTAMP_EN; _CLKGATECTRL |= _CLKGATECTRL_TIMESTAMP_EN;
/* minimum 3 clk delay is required before timer register access */ /* minimum 3 clk delay is required before timer register access */
task_sleep(3); task_sleep(3);
_TIMESTAMP_CTRL = 0x0; /* disable/reset timer */ _TIMESTAMP_CTRL = 0x0; /* disable/reset timer */
@ -100,7 +100,7 @@ void _TimestampOpen(void)
_TIMESTAMP_ICLEAR = 0x70F; /* clear all interrupt status */ _TIMESTAMP_ICLEAR = 0x70F; /* clear all interrupt status */
_TIMESTAMP_CTRL = 0x1; /* enable timer */ _TIMESTAMP_CTRL = 0x1; /* enable timer */
} }
/******************************************************************************* /*******************************************************************************
* *
@ -114,30 +114,30 @@ void _TimestampOpen(void)
*/ */
uint32_t _TimestampRead(void) uint32_t _TimestampRead(void)
{ {
static uint32_t lastTimerVal = 0; static uint32_t lastTimerVal = 0;
static uint32_t cnt = 0; static uint32_t cnt = 0;
uint32_t timerVal = _TIMESTAMP_VAL; uint32_t timerVal = _TIMESTAMP_VAL;
/* handle rollover for every other read (end of sleep) */ /* handle rollover for every other read (end of sleep) */
if ((cnt % 2) && (timerVal > lastTimerVal)) { if ((cnt % 2) && (timerVal > lastTimerVal)) {
lastTimerVal = timerVal; lastTimerVal = timerVal;
/* convert to extended up-counter value */ /* convert to extended up-counter value */
timerVal = _TIMESTAMP_EXT + (_TIMESTAMP_MAX - timerVal); timerVal = _TIMESTAMP_EXT + (_TIMESTAMP_MAX - timerVal);
} }
else { else {
lastTimerVal = timerVal; lastTimerVal = timerVal;
/* convert to up-counter value */ /* convert to up-counter value */
timerVal = _TIMESTAMP_MAX - timerVal; timerVal = _TIMESTAMP_MAX - timerVal;
} }
cnt++; cnt++;
return timerVal; return timerVal;
} }
/******************************************************************************* /*******************************************************************************
* *
@ -151,15 +151,15 @@ uint32_t _TimestampRead(void)
*/ */
void _TimestampClose(void) void _TimestampClose(void)
{ {
/* disable/reset timer */ /* disable/reset timer */
_TIMESTAMP_CTRL = 0x0; _TIMESTAMP_CTRL = 0x0;
_TIMESTAMP_CFG = 0x0; _TIMESTAMP_CFG = 0x0;
/* disable timer access */ /* disable timer access */
_CLKGATECTRL &= ~_CLKGATECTRL_TIMESTAMP_EN; _CLKGATECTRL &= ~_CLKGATECTRL_TIMESTAMP_EN;
} }
#elif defined(CONFIG_BSP_FSL_FRDM_K64F) #elif defined(CONFIG_BSP_FSL_FRDM_K64F)
/* Freescale FRDM-K64F target - use RTC (prescale value) */ /* Freescale FRDM-K64F target - use RTC (prescale value) */
@ -198,11 +198,11 @@ void _TimestampClose(void)
*/ */
void _TimestampOpen(void) void _TimestampOpen(void)
{ {
/* enable timer access */ /* enable timer access */
_CLKGATECTRL |= _CLKGATECTRL_TIMESTAMP_EN; _CLKGATECTRL |= _CLKGATECTRL_TIMESTAMP_EN;
/* set 32 KHz RTC clk */ /* set 32 KHz RTC clk */
_SYSOPTCTRL2 |= _SYSOPTCTRL2_32KHZRTCCLK; _SYSOPTCTRL2 |= _SYSOPTCTRL2_32KHZRTCCLK;
_TIMESTAMP_STATUS = 0x0; /* disable counter */ _TIMESTAMP_STATUS = 0x0; /* disable counter */
@ -215,13 +215,13 @@ void _TimestampOpen(void)
_TIMESTAMP_WACCESS = 0xFF; /* allow register write access */ _TIMESTAMP_WACCESS = 0xFF; /* allow register write access */
_TIMESTAMP_IMASK = 0x0; /* mask all timer interrupts */ _TIMESTAMP_IMASK = 0x0; /* mask all timer interrupts */
/* minimum 0.3 sec delay required for oscillator stabilization */ /* minimum 0.3 sec delay required for oscillator stabilization */
task_sleep(300000/sys_clock_us_per_tick); task_sleep(300000/sys_clock_us_per_tick);
_TIMESTAMP_VAL = 0x0; /* clear invalid time flag in status register */ _TIMESTAMP_VAL = 0x0; /* clear invalid time flag in status register */
_TIMESTAMP_STATUS = 0x10; /* enable counter */ _TIMESTAMP_STATUS = 0x10; /* enable counter */
} }
/******************************************************************************* /*******************************************************************************
* *
@ -235,30 +235,30 @@ void _TimestampOpen(void)
*/ */
uint32_t _TimestampRead(void) uint32_t _TimestampRead(void)
{ {
static uint32_t lastPrescale = 0; static uint32_t lastPrescale = 0;
static uint32_t cnt = 0; static uint32_t cnt = 0;
uint32_t prescale1 = _TIMESTAMP_PRESCALE; uint32_t prescale1 = _TIMESTAMP_PRESCALE;
uint32_t prescale2 = _TIMESTAMP_PRESCALE; uint32_t prescale2 = _TIMESTAMP_PRESCALE;
/* ensure a valid reading */ /* ensure a valid reading */
while (prescale1 != prescale2) { while (prescale1 != prescale2) {
prescale1 = _TIMESTAMP_PRESCALE; prescale1 = _TIMESTAMP_PRESCALE;
prescale2 = _TIMESTAMP_PRESCALE; prescale2 = _TIMESTAMP_PRESCALE;
} }
/* handle prescale rollover @ 0x8000 for every other read (end of sleep) */ /* handle prescale rollover @ 0x8000 for every other read (end of sleep) */
if ((cnt % 2) && (prescale1 < lastPrescale)) { if ((cnt % 2) && (prescale1 < lastPrescale)) {
prescale1 += 0x8000; prescale1 += 0x8000;
} }
lastPrescale = prescale2; lastPrescale = prescale2;
cnt++; cnt++;
return prescale1; return prescale1;
} }
/******************************************************************************* /*******************************************************************************
* *
@ -272,10 +272,10 @@ uint32_t _TimestampRead(void)
*/ */
void _TimestampClose(void) void _TimestampClose(void)
{ {
_TIMESTAMP_STATUS = 0x0; /* disable counter */ _TIMESTAMP_STATUS = 0x0; /* disable counter */
_TIMESTAMP_CTRL = 0x0; /* disable oscillator */ _TIMESTAMP_CTRL = 0x0; /* disable oscillator */
} }
#else #else
#error "Unknown BSP" #error "Unknown BSP"

View file

@ -128,7 +128,7 @@ int testLowTimerPeriodicity(void)
} }
(void) task_tick_delta_32(&refTime); (void) task_tick_delta_32(&refTime);
/* Use task_timer_restart() to change the periodicity */ /* Use task_timer_restart() to change the periodicity */
task_timer_restart(pTimer[0], 0, 60); task_timer_restart(pTimer[0], 0, 60);
for (i = 0; i < 6; i++) { for (i = 0; i < 6; i++) {
status = task_sem_take_wait_timeout(TIMER_SEM, 100); status = task_sem_take_wait_timeout(TIMER_SEM, 100);

View file

@ -66,27 +66,27 @@ void main(void)
void RegressionTaskEntry(void) void RegressionTaskEntry(void)
#endif #endif
{ {
int tcRC = TC_PASS; int tcRC = TC_PASS;
int i; int i;
PRINT_DATA("Starting XIP tests\n"); PRINT_DATA("Starting XIP tests\n");
PRINT_LINE; PRINT_LINE;
/* Test globals are correct */ /* Test globals are correct */
TC_PRINT("Test globals\n"); TC_PRINT("Test globals\n");
/* Array should be filled with monotomically incrementing values */ /* Array should be filled with monotomically incrementing values */
for (i = 0; i < XIP_TEST_ARRAY_SZ; i++) { for (i = 0; i < XIP_TEST_ARRAY_SZ; i++) {
if (xip_array[i] != (i+1)) { if (xip_array[i] != (i+1)) {
TC_PRINT("xip_array[%d] != %d\n", i, i+1); TC_PRINT("xip_array[%d] != %d\n", i, i+1);
tcRC = TC_FAIL; tcRC = TC_FAIL;
goto exitRtn; goto exitRtn;
} }
} }
exitRtn: exitRtn:
TC_END_RESULT(tcRC); TC_END_RESULT(tcRC);
TC_END_REPORT(tcRC); TC_END_REPORT(tcRC);
} }

View file

@ -87,24 +87,24 @@ static char pStack[FIBER_STACK_SIZE];
/* pointer array ensures specified functions are linked into the image */ /* pointer array ensures specified functions are linked into the image */
volatile pfunc func_array[] = { volatile pfunc func_array[] = {
/* nano timer functions */ /* nano timer functions */
(pfunc)nano_timer_init, (pfunc)nano_timer_init,
(pfunc)nano_fiber_timer_start, (pfunc)nano_fiber_timer_start,
(pfunc)nano_fiber_timer_wait, (pfunc)nano_fiber_timer_wait,
/* nano semaphore functions */ /* nano semaphore functions */
(pfunc)nano_sem_init, (pfunc)nano_sem_init,
(pfunc)nano_fiber_sem_take_wait, (pfunc)nano_fiber_sem_take_wait,
(pfunc)nano_fiber_sem_give, (pfunc)nano_fiber_sem_give,
#ifdef TEST_max #ifdef TEST_max
/* nano LIFO functions */ /* nano LIFO functions */
(pfunc)nano_lifo_init, (pfunc)nano_lifo_init,
(pfunc)nano_fiber_lifo_put, (pfunc)nano_fiber_lifo_put,
(pfunc)nano_fiber_lifo_get, (pfunc)nano_fiber_lifo_get,
/* nano stack functions */ /* nano stack functions */
(pfunc)nano_stack_init, (pfunc)nano_stack_init,
(pfunc)nano_fiber_stack_push, (pfunc)nano_fiber_stack_push,
(pfunc)nano_fiber_stack_pop, (pfunc)nano_fiber_stack_pop,
/* nano FIFO functions */ /* nano FIFO functions */
(pfunc)nano_fifo_init, (pfunc)nano_fifo_init,
(pfunc)nano_fiber_fifo_put, (pfunc)nano_fiber_fifo_put,
(pfunc)nano_fiber_fifo_get, (pfunc)nano_fiber_fifo_get,
@ -119,9 +119,9 @@ volatile pfunc func_array[] = {
*/ */
void dummyIsr(void *unused) void dummyIsr(void *unused)
{ {
ARG_UNUSED(unused); ARG_UNUSED(unused);
} }
#ifdef TEST_reg #ifdef TEST_reg
/******************************************************************************* /*******************************************************************************
@ -136,28 +136,27 @@ void dummyIsr(void *unused)
*/ */
static void isrDummyIntStub(void *unused) static void isrDummyIntStub(void *unused)
{ {
ARG_UNUSED(unused); ARG_UNUSED(unused);
isr_dummy(); isr_dummy();
CODE_UNREACHABLE; CODE_UNREACHABLE;
} }
#endif /* TEST_reg */ #endif /* TEST_reg */
/******************************************************************************* /*******************************************************************************
* *
* fiberEntry - trivial fiber * fiberEntry - trivial fiber
* *
* @param message Message to be printed.
* @param arg1 Unused.
*
* RETURNS: N/A * RETURNS: N/A
*/ */
static void fiberEntry static void fiberEntry(int message, int arg1)
( {
int message, /* message to be printed */
int arg1 /* unused */
)
{
ARG_UNUSED(arg1); ARG_UNUSED(arg1);
#ifdef TEST_max #ifdef TEST_max
@ -165,7 +164,7 @@ static void fiberEntry
#else #else
printk((char *)message); printk((char *)message);
#endif /* TEST_max */ #endif /* TEST_max */
} }
#endif /* !TEST_min */ #endif /* !TEST_min */
@ -180,19 +179,19 @@ static void fiberEntry
*/ */
void main(void) void main(void)
{ {
#ifdef TEST_max #ifdef TEST_max
/* dynamically link in dummy ISR */ /* dynamically link in dummy ISR */
irq_connect(NANO_SOFT_IRQ, IRQ_PRIORITY, dummyIsr, irq_connect(NANO_SOFT_IRQ, IRQ_PRIORITY, dummyIsr,
(void *) 0, isrDummyHandlerStub); (void *) 0, isrDummyHandlerStub);
#endif /* TEST_max */ #endif /* TEST_max */
#ifndef TEST_min #ifndef TEST_min
/* start a trivial fiber */ /* start a trivial fiber */
task_fiber_start(pStack, FIBER_STACK_SIZE, fiberEntry, (int) MESSAGE, task_fiber_start(pStack, FIBER_STACK_SIZE, fiberEntry, (int) MESSAGE,
(int) func_array, 10, 0); (int) func_array, 10, 0);
#endif /* !TEST_min */ #endif /* !TEST_min */
while (1) { while (1) {
i++; i++;
}
} }
}

View file

@ -42,7 +42,7 @@ static inline void isr_dummy(void)
extern void _IntEnt(void); extern void _IntEnt(void);
extern void _IntExit(void); extern void _IntExit(void);
/* compiler-generated preamble pushes & modifies EBP */ /* compiler-generated preamble pushes & modifies EBP */
__asm__ volatile ( __asm__ volatile (
"pop %%ebp;\n\t" "pop %%ebp;\n\t"
"call _IntEnt;\n\t" "call _IntEnt;\n\t"

View file

@ -47,26 +47,26 @@ static struct nano_fifo nanoFifo_sync; /* for synchronization */
*/ */
void lifo_test_init(void) void lifo_test_init(void)
{ {
nano_lifo_init(&nanoLifo1); nano_lifo_init(&nanoLifo1);
nano_lifo_init(&nanoLifo2); nano_lifo_init(&nanoLifo2);
} }
/******************************************************************************* /*******************************************************************************
* *
* lifo_fiber1 - lifo test context * lifo_fiber1 - lifo test context
* *
* @param par1 Ignored parameter.
* @param par2 Number of test loops.
*
* RETURNS: N/A * RETURNS: N/A
* *
* \NOMANUAL * \NOMANUAL
*/ */
void lifo_fiber1( void lifo_fiber1(int par1, int par2)
int par1, /* ignored parameter */ {
int par2 /* number of test loops */
)
{
int i; int i;
int element_a[2]; int element_a[2];
int element_b[2]; int element_b[2];
@ -75,84 +75,89 @@ void lifo_fiber1(
ARG_UNUSED(par1); ARG_UNUSED(par1);
for (i = 0; i < par2 / 2; i++) { for (i = 0; i < par2 / 2; i++) {
pelement = (int *) nano_fiber_lifo_get_wait(&nanoLifo1); pelement = (int *) nano_fiber_lifo_get_wait(&nanoLifo1);
if (pelement[1] != 2 * i) if (pelement[1] != 2 * i) {
break; break;
element_a[1] = 2 * i; }
nano_fiber_lifo_put(&nanoLifo2, element_a); element_a[1] = 2 * i;
pelement = (int *) nano_fiber_lifo_get_wait(&nanoLifo1); nano_fiber_lifo_put(&nanoLifo2, element_a);
if (pelement[1] != 2 * i + 1) pelement = (int *) nano_fiber_lifo_get_wait(&nanoLifo1);
break; if (pelement[1] != 2 * i + 1) {
element_b[1] = 2 * i + 1; break;
nano_fiber_lifo_put(&nanoLifo2, element_b); }
element_b[1] = 2 * i + 1;
nano_fiber_lifo_put(&nanoLifo2, element_b);
} }
/* wait till it is safe to end: */ /* wait till it is safe to end: */
nano_fiber_fifo_get_wait(&nanoFifo_sync); nano_fiber_fifo_get_wait(&nanoFifo_sync);
} }
/******************************************************************************* /*******************************************************************************
* *
* lifo_fiber2 - lifo test context * lifo_fiber2 - lifo test context
* *
* @param par1 Address of the counter.
* @param par2 Number of test cycles.
*
* RETURNS: N/A * RETURNS: N/A
* *
* \NOMANUAL * \NOMANUAL
*/ */
void lifo_fiber2( void lifo_fiber2(int par1, int par2)
int par1, /* address of the counter */ {
int par2 /* number of test cycles */
)
{
int i; int i;
int element[2]; int element[2];
int * pelement; int * pelement;
int * pcounter = (int *) par1; int * pcounter = (int *) par1;
for (i = 0; i < par2; i++) { for (i = 0; i < par2; i++) {
element[1] = i; element[1] = i;
nano_fiber_lifo_put(&nanoLifo1, element); nano_fiber_lifo_put(&nanoLifo1, element);
pelement = (int *) nano_fiber_lifo_get_wait(&nanoLifo2); pelement = (int *) nano_fiber_lifo_get_wait(&nanoLifo2);
if (pelement[1] != i) if (pelement[1] != i) {
break; break;
(*pcounter)++; }
(*pcounter)++;
} }
/* wait till it is safe to end: */ /* wait till it is safe to end: */
nano_fiber_fifo_get_wait(&nanoFifo_sync); nano_fiber_fifo_get_wait(&nanoFifo_sync);
} }
/******************************************************************************* /*******************************************************************************
* *
* lifo_fiber3 - lifo test context * lifo_fiber3 - lifo test context
* *
* @param par1 Address of the counter.
* @param par2 Number of test loops.
*
* RETURNS: N/A * RETURNS: N/A
* *
* \NOMANUAL * \NOMANUAL
*/ */
void lifo_fiber3( void lifo_fiber3(int par1, int par2)
int par1, /* address of the counter */ {
int par2 /* number of test loops */
)
{
int i; int i;
int element[2]; int element[2];
int * pelement; int * pelement;
int * pcounter = (int *) par1; int * pcounter = (int *) par1;
for (i = 0; i < par2; i++) { for (i = 0; i < par2; i++) {
element[1] = i; element[1] = i;
nano_fiber_lifo_put(&nanoLifo1, element); nano_fiber_lifo_put(&nanoLifo1, element);
while (NULL == (pelement = (int *) nano_fiber_lifo_get(&nanoLifo2))) while (NULL == (pelement = (int *) nano_fiber_lifo_get(&nanoLifo2))) {
fiber_yield(); fiber_yield();
if (pelement[1] != i) }
break; if (pelement[1] != i) {
(*pcounter)++; break;
}
(*pcounter)++;
} }
/* wait till it is safe to end: */ /* wait till it is safe to end: */
nano_fiber_fifo_get_wait(&nanoFifo_sync); nano_fiber_fifo_get_wait(&nanoFifo_sync);
} }
/******************************************************************************* /*******************************************************************************
* *
@ -164,7 +169,7 @@ void lifo_fiber3(
*/ */
int lifo_test(void) int lifo_test(void)
{ {
uint32_t t; uint32_t t;
int i = 0; int i = 0;
int return_value = 0; int return_value = 0;
@ -173,12 +178,12 @@ int lifo_test(void)
nano_fifo_init(&nanoFifo_sync); nano_fifo_init(&nanoFifo_sync);
/* test get wait & put fiber functions */ /* test get wait & put fiber functions */
fprintf(output_file, sz_test_case_fmt, fprintf(output_file, sz_test_case_fmt,
"LIFO channel - 'nano_fiber_lifo_get_wait'"); "LIFO channel - 'nano_fiber_lifo_get_wait'");
fprintf(output_file, sz_description, fprintf(output_file, sz_description,
"testing 'nano_lifo_init','nano_fiber_lifo_get_wait'," "testing 'nano_lifo_init','nano_fiber_lifo_get_wait',"
" 'nano_fiber_lifo_put' functions;"); " 'nano_fiber_lifo_put' functions;");
printf(sz_test_start_fmt, "'nano_fiber_lifo_get_wait'"); printf(sz_test_start_fmt, "'nano_fiber_lifo_get_wait'");
lifo_test_init(); lifo_test_init();
@ -186,26 +191,27 @@ int lifo_test(void)
t = BENCH_START(); t = BENCH_START();
task_fiber_start(fiber_stack1, STACK_SIZE, lifo_fiber1, 0, task_fiber_start(fiber_stack1, STACK_SIZE, lifo_fiber1, 0,
NUMBER_OF_LOOPS, 3, 0); NUMBER_OF_LOOPS, 3, 0);
task_fiber_start(fiber_stack2, STACK_SIZE, lifo_fiber2, (int) &i, task_fiber_start(fiber_stack2, STACK_SIZE, lifo_fiber2, (int) &i,
NUMBER_OF_LOOPS, 3, 0); NUMBER_OF_LOOPS, 3, 0);
t = TIME_STAMP_DELTA_GET(t); t = TIME_STAMP_DELTA_GET(t);
return_value += check_result(i, t); return_value += check_result(i, t);
/* fiber contexts have done their job, they can stop now safely: */ /* fiber contexts have done their job, they can stop now safely: */
for (j = 0; j < 2; j++) for (j = 0; j < 2; j++) {
nano_task_fifo_put(&nanoFifo_sync, (void *) element); nano_task_fifo_put(&nanoFifo_sync, (void *) element);
}
/* test get/yield & put fiber functions */ /* test get/yield & put fiber functions */
fprintf(output_file, sz_test_case_fmt, fprintf(output_file, sz_test_case_fmt,
"LIFO channel - 'nano_fiber_lifo_get'"); "LIFO channel - 'nano_fiber_lifo_get'");
fprintf(output_file, sz_description, fprintf(output_file, sz_description,
"testing 'nano_lifo_init','nano_fiber_lifo_get_wait'," "testing 'nano_lifo_init','nano_fiber_lifo_get_wait',"
" 'nano_fiber_lifo_get',\n"); " 'nano_fiber_lifo_get',\n");
fprintf(output_file, fprintf(output_file,
"\t'nano_fiber_lifo_put', 'fiber_yield' functions;"); "\t'nano_fiber_lifo_put', 'fiber_yield' functions;");
printf(sz_test_start_fmt, "'nano_fiber_lifo_get'"); printf(sz_test_start_fmt, "'nano_fiber_lifo_get'");
lifo_test_init(); lifo_test_init();
@ -214,24 +220,25 @@ int lifo_test(void)
i = 0; i = 0;
task_fiber_start(fiber_stack1, STACK_SIZE, lifo_fiber1, 0, task_fiber_start(fiber_stack1, STACK_SIZE, lifo_fiber1, 0,
NUMBER_OF_LOOPS, 3, 0); NUMBER_OF_LOOPS, 3, 0);
task_fiber_start(fiber_stack2, STACK_SIZE, lifo_fiber3, (int) &i, task_fiber_start(fiber_stack2, STACK_SIZE, lifo_fiber3, (int) &i,
NUMBER_OF_LOOPS, 3, 0); NUMBER_OF_LOOPS, 3, 0);
t = TIME_STAMP_DELTA_GET(t); t = TIME_STAMP_DELTA_GET(t);
return_value += check_result(i, t); return_value += check_result(i, t);
/* fiber contexts have done their job, they can stop now safely: */ /* fiber contexts have done their job, they can stop now safely: */
for (j = 0; j < 2; j++) for (j = 0; j < 2; j++) {
nano_task_fifo_put(&nanoFifo_sync, (void *) element); nano_task_fifo_put(&nanoFifo_sync, (void *) element);
}
/* test get wait & put fiber/task functions */ /* test get wait & put fiber/task functions */
fprintf(output_file, sz_test_case_fmt, fprintf(output_file, sz_test_case_fmt,
"LIFO channel - 'nano_task_lifo_get_wait'"); "LIFO channel - 'nano_task_lifo_get_wait'");
fprintf(output_file, sz_description, fprintf(output_file, sz_description,
"testing 'nano_lifo_init','nano_fiber_lifo_get_wait'," "testing 'nano_lifo_init','nano_fiber_lifo_get_wait',"
" 'nano_fiber_lifo_put',\n"); " 'nano_fiber_lifo_put',\n");
fprintf(output_file, "\t'nano_task_lifo_get_wait', 'nano_task_lifo_put' functions;"); fprintf(output_file, "\t'nano_task_lifo_get_wait', 'nano_task_lifo_put' functions;");
printf(sz_test_start_fmt, "'nano_task_lifo_get_wait'"); printf(sz_test_start_fmt, "'nano_task_lifo_get_wait'");
@ -240,30 +247,33 @@ int lifo_test(void)
t = BENCH_START(); t = BENCH_START();
task_fiber_start(fiber_stack1, STACK_SIZE, lifo_fiber1, 0, task_fiber_start(fiber_stack1, STACK_SIZE, lifo_fiber1, 0,
NUMBER_OF_LOOPS, 3, 0); NUMBER_OF_LOOPS, 3, 0);
for (i = 0; i < NUMBER_OF_LOOPS / 2; i++) { for (i = 0; i < NUMBER_OF_LOOPS / 2; i++) {
int element[2]; int element[2];
int * pelement; int * pelement;
element[1] = 2 * i; element[1] = 2 * i;
nano_task_lifo_put(&nanoLifo1, element); nano_task_lifo_put(&nanoLifo1, element);
element[1] = 2 * i + 1; element[1] = 2 * i + 1;
nano_task_lifo_put(&nanoLifo1, element); nano_task_lifo_put(&nanoLifo1, element);
pelement = (int *) nano_task_lifo_get_wait(&nanoLifo2); pelement = (int *) nano_task_lifo_get_wait(&nanoLifo2);
if (pelement[1] != 2 * i + 1) if (pelement[1] != 2 * i + 1) {
break; break;
pelement = (int *) nano_task_lifo_get_wait(&nanoLifo2); }
if (pelement[1] != 2 * i) pelement = (int *) nano_task_lifo_get_wait(&nanoLifo2);
break; if (pelement[1] != 2 * i) {
break;
}
} }
t = TIME_STAMP_DELTA_GET(t); t = TIME_STAMP_DELTA_GET(t);
return_value += check_result(i * 2, t); return_value += check_result(i * 2, t);
/* fiber contexts have done their job, they can stop now safely: */ /* fiber contexts have done their job, they can stop now safely: */
for (j = 0; j < 2; j++) for (j = 0; j < 2; j++) {
nano_task_fifo_put(&nanoFifo_sync, (void *) element); nano_task_fifo_put(&nanoFifo_sync, (void *) element);
}
return return_value; return return_value;
} }

View file

@ -48,10 +48,10 @@ static struct nano_fifo nanoFifo_sync; /* for synchronization */
*/ */
void fifo_test_init(void) void fifo_test_init(void)
{ {
nano_fifo_init(&nanoFifo1); nano_fifo_init(&nanoFifo1);
nano_fifo_init(&nanoFifo2); nano_fifo_init(&nanoFifo2);
} }
/******************************************************************************* /*******************************************************************************
@ -60,29 +60,30 @@ void fifo_test_init(void)
* *
* RETURNS: N/A * RETURNS: N/A
* *
* @param par1 Ignored parameter.
* @param par2 Number of test loops.
*
* \NOMANUAL * \NOMANUAL
*/ */
void fifo_fiber1( void fifo_fiber1(int par1, int par2)
int par1, /* ignored parameter */ {
int par2 /* number of test loops */
)
{
int i; int i;
int element[2]; int element[2];
int * pelement; int * pelement;
ARG_UNUSED(par1); ARG_UNUSED(par1);
for (i = 0; i < par2; i++) { for (i = 0; i < par2; i++) {
pelement = (int *) nano_fiber_fifo_get_wait(&nanoFifo1); pelement = (int *) nano_fiber_fifo_get_wait(&nanoFifo1);
if (pelement[1] != i) if (pelement[1] != i) {
break; break;
element[1] = i; }
nano_fiber_fifo_put(&nanoFifo2, element); element[1] = i;
nano_fiber_fifo_put(&nanoFifo2, element);
} }
/* wait till it is safe to end: */ /* wait till it is safe to end: */
nano_fiber_fifo_get_wait(&nanoFifo_sync); nano_fiber_fifo_get_wait(&nanoFifo_sync);
} }
/******************************************************************************* /*******************************************************************************
@ -91,30 +92,31 @@ void fifo_fiber1(
* *
* RETURNS: N/A * RETURNS: N/A
* *
* @param par1 Address of the counter.
* @param par2 Number of test cycles.
*
* \NOMANUAL * \NOMANUAL
*/ */
void fifo_fiber2( void fifo_fiber2(int par1, int par2)
int par1, /* address of the counter */ {
int par2 /* number of test cycles */
)
{
int i; int i;
int element[2]; int element[2];
int * pelement; int * pelement;
int * pcounter = (int *) par1; int * pcounter = (int *) par1;
for (i = 0; i < par2; i++) { for (i = 0; i < par2; i++) {
element[1] = i; element[1] = i;
nano_fiber_fifo_put(&nanoFifo1, element); nano_fiber_fifo_put(&nanoFifo1, element);
pelement = (int *) nano_fiber_fifo_get_wait(&nanoFifo2); pelement = (int *) nano_fiber_fifo_get_wait(&nanoFifo2);
if (pelement[1] != i) if (pelement[1] != i) {
break; break;
(*pcounter)++; }
(*pcounter)++;
} }
/* wait till it is safe to end: */ /* wait till it is safe to end: */
nano_fiber_fifo_get_wait(&nanoFifo_sync); nano_fiber_fifo_get_wait(&nanoFifo_sync);
} }
/******************************************************************************* /*******************************************************************************
@ -123,31 +125,33 @@ void fifo_fiber2(
* *
* RETURNS: N/A * RETURNS: N/A
* *
* @param par1 Address of the counter.
* @param par2 Number of test cycles.
*
* \NOMANUAL * \NOMANUAL
*/ */
void fifo_fiber3( void fifo_fiber3(int par1, int par2)
int par1, /* address of the counter */ {
int par2 /* number of test cycles */
)
{
int i; int i;
int element[2]; int element[2];
int * pelement; int * pelement;
int * pcounter = (int *) par1; int * pcounter = (int *) par1;
for (i = 0; i < par2; i++) { for (i = 0; i < par2; i++) {
element[1] = i; element[1] = i;
nano_fiber_fifo_put(&nanoFifo1, element); nano_fiber_fifo_put(&nanoFifo1, element);
while (NULL == (pelement = (int *) nano_fiber_fifo_get(&nanoFifo2))) while (NULL == (pelement = (int *) nano_fiber_fifo_get(&nanoFifo2))) {
fiber_yield(); fiber_yield();
if (pelement[1] != i) }
break; if (pelement[1] != i) {
(*pcounter)++; break;
}
(*pcounter)++;
} }
/* wait till it is safe to end: */ /* wait till it is safe to end: */
nano_fiber_fifo_get_wait(&nanoFifo_sync); nano_fiber_fifo_get_wait(&nanoFifo_sync);
} }
/******************************************************************************* /*******************************************************************************
@ -160,7 +164,7 @@ void fifo_fiber3(
*/ */
int fifo_test(void) int fifo_test(void)
{ {
uint32_t t; uint32_t t;
int i = 0; int i = 0;
int return_value = 0; int return_value = 0;
@ -169,12 +173,12 @@ int fifo_test(void)
nano_fifo_init(&nanoFifo_sync); nano_fifo_init(&nanoFifo_sync);
/* test get wait & put fiber functions */ /* test get wait & put fiber functions */
fprintf(output_file, sz_test_case_fmt, fprintf(output_file, sz_test_case_fmt,
"FIFO channel - 'nano_fiber_fifo_get_wait'"); "FIFO channel - 'nano_fiber_fifo_get_wait'");
fprintf(output_file, sz_description, fprintf(output_file, sz_description,
"testing 'nano_fifo_init','nano_fiber_fifo_get_wait'," "testing 'nano_fifo_init','nano_fiber_fifo_get_wait',"
" 'nano_fiber_fifo_put' functions;"); " 'nano_fiber_fifo_put' functions;");
printf(sz_test_start_fmt, "'nano_fiber_fifo_get_wait'"); printf(sz_test_start_fmt, "'nano_fiber_fifo_get_wait'");
fifo_test_init(); fifo_test_init();
@ -182,26 +186,27 @@ int fifo_test(void)
t = BENCH_START(); t = BENCH_START();
task_fiber_start(fiber_stack1, STACK_SIZE, fifo_fiber1, 0, task_fiber_start(fiber_stack1, STACK_SIZE, fifo_fiber1, 0,
NUMBER_OF_LOOPS, 3, 0); NUMBER_OF_LOOPS, 3, 0);
task_fiber_start(fiber_stack2, STACK_SIZE, fifo_fiber2, (int) &i, task_fiber_start(fiber_stack2, STACK_SIZE, fifo_fiber2, (int) &i,
NUMBER_OF_LOOPS, 3, 0); NUMBER_OF_LOOPS, 3, 0);
t = TIME_STAMP_DELTA_GET(t); t = TIME_STAMP_DELTA_GET(t);
return_value += check_result(i, t); return_value += check_result(i, t);
/* fiber contexts have done their job, they can stop now safely: */ /* fiber contexts have done their job, they can stop now safely: */
for (j = 0; j < 2; j++) for (j = 0; j < 2; j++) {
nano_task_fifo_put(&nanoFifo_sync, (void *) element); nano_task_fifo_put(&nanoFifo_sync, (void *) element);
}
/* test get/yield & put fiber functions */ /* test get/yield & put fiber functions */
fprintf(output_file, sz_test_case_fmt, fprintf(output_file, sz_test_case_fmt,
"FIFO channel - 'nano_fiber_fifo_get'"); "FIFO channel - 'nano_fiber_fifo_get'");
fprintf(output_file, sz_description, fprintf(output_file, sz_description,
"testing 'nano_fifo_init','nano_fiber_fifo_get_wait'," "testing 'nano_fifo_init','nano_fiber_fifo_get_wait',"
" 'nano_fiber_fifo_get',\n"); " 'nano_fiber_fifo_get',\n");
fprintf(output_file, fprintf(output_file,
"\t'nano_fiber_fifo_put', 'fiber_yield' functions;"); "\t'nano_fiber_fifo_put', 'fiber_yield' functions;");
printf(sz_test_start_fmt, "'nano_fiber_fifo_get'"); printf(sz_test_start_fmt, "'nano_fiber_fifo_get'");
fifo_test_init(); fifo_test_init();
@ -210,26 +215,27 @@ int fifo_test(void)
i = 0; i = 0;
task_fiber_start(fiber_stack1, STACK_SIZE, fifo_fiber1, 0, task_fiber_start(fiber_stack1, STACK_SIZE, fifo_fiber1, 0,
NUMBER_OF_LOOPS, 3, 0); NUMBER_OF_LOOPS, 3, 0);
task_fiber_start(fiber_stack2, STACK_SIZE, fifo_fiber3, (int) &i, task_fiber_start(fiber_stack2, STACK_SIZE, fifo_fiber3, (int) &i,
NUMBER_OF_LOOPS, 3, 0); NUMBER_OF_LOOPS, 3, 0);
t = TIME_STAMP_DELTA_GET(t); t = TIME_STAMP_DELTA_GET(t);
return_value += check_result(i, t); return_value += check_result(i, t);
/* fiber contexts have done their job, they can stop now safely: */ /* fiber contexts have done their job, they can stop now safely: */
for (j = 0; j < 2; j++) for (j = 0; j < 2; j++) {
nano_task_fifo_put(&nanoFifo_sync, (void *) element); nano_task_fifo_put(&nanoFifo_sync, (void *) element);
}
/* test get wait & put fiber/task functions */ /* test get wait & put fiber/task functions */
fprintf(output_file, sz_test_case_fmt, fprintf(output_file, sz_test_case_fmt,
"FIFO channel - 'nano_task_fifo_get_wait'"); "FIFO channel - 'nano_task_fifo_get_wait'");
fprintf(output_file, sz_description, fprintf(output_file, sz_description,
"testing 'nano_fifo_init','nano_fiber_fifo_get_wait'," "testing 'nano_fifo_init','nano_fiber_fifo_get_wait',"
" 'nano_fiber_fifo_put',\n"); " 'nano_fiber_fifo_put',\n");
fprintf(output_file, fprintf(output_file,
"\t'nano_task_fifo_get_wait', 'nano_task_fifo_put' functions;"); "\t'nano_task_fifo_get_wait', 'nano_task_fifo_put' functions;");
printf(sz_test_start_fmt, "'nano_task_fifo_get_wait'"); printf(sz_test_start_fmt, "'nano_task_fifo_get_wait'");
fifo_test_init(); fifo_test_init();
@ -237,31 +243,34 @@ int fifo_test(void)
t = BENCH_START(); t = BENCH_START();
task_fiber_start(fiber_stack1, STACK_SIZE, fifo_fiber1, 0, task_fiber_start(fiber_stack1, STACK_SIZE, fifo_fiber1, 0,
NUMBER_OF_LOOPS / 2, 3, 0); NUMBER_OF_LOOPS / 2, 3, 0);
task_fiber_start(fiber_stack2, STACK_SIZE, fifo_fiber1, 0, task_fiber_start(fiber_stack2, STACK_SIZE, fifo_fiber1, 0,
NUMBER_OF_LOOPS / 2, 3, 0); NUMBER_OF_LOOPS / 2, 3, 0);
for (i = 0; i < NUMBER_OF_LOOPS / 2; i++) { for (i = 0; i < NUMBER_OF_LOOPS / 2; i++) {
int element[2]; int element[2];
int * pelement; int * pelement;
element[1] = i; element[1] = i;
nano_task_fifo_put(&nanoFifo1, element); nano_task_fifo_put(&nanoFifo1, element);
element[1] = i; element[1] = i;
nano_task_fifo_put(&nanoFifo1, element); nano_task_fifo_put(&nanoFifo1, element);
pelement = (int *) nano_task_fifo_get_wait(&nanoFifo2); pelement = (int *) nano_task_fifo_get_wait(&nanoFifo2);
if (pelement[1] != i) if (pelement[1] != i) {
break; break;
pelement = (int *) nano_task_fifo_get_wait(&nanoFifo2); }
if (pelement[1] != i) pelement = (int *) nano_task_fifo_get_wait(&nanoFifo2);
break; if (pelement[1] != i) {
break;
}
} }
t = TIME_STAMP_DELTA_GET(t); t = TIME_STAMP_DELTA_GET(t);
return_value += check_result(i * 2, t); return_value += check_result(i * 2, t);
/* fiber contexts have done their job, they can stop now safely: */ /* fiber contexts have done their job, they can stop now safely: */
for (j = 0; j < 2; j++) for (j = 0; j < 2; j++) {
nano_task_fifo_put(&nanoFifo_sync, (void *) element); nano_task_fifo_put(&nanoFifo_sync, (void *) element);
}
return return_value; return return_value;
} }

View file

@ -45,85 +45,86 @@ struct nano_sem nanoSem2;
*/ */
void sema_test_init(void) void sema_test_init(void)
{ {
nano_sem_init(&nanoSem1); nano_sem_init(&nanoSem1);
nano_sem_init(&nanoSem2); nano_sem_init(&nanoSem2);
} }
/******************************************************************************* /*******************************************************************************
* *
* sema_fiber1 - semaphore test context * sema_fiber1 - semaphore test context
* *
* @param par1 Ignored parameter.
* @param par2 Number of test loops.
*
* RETURNS: N/A * RETURNS: N/A
* *
* \NOMANUAL * \NOMANUAL
*/ */
void sema_fiber1( void sema_fiber1(int par1, int par2)
int par1, /* ignored parameter */ {
int par2 /* number of test loops */
)
{
int i; int i;
ARG_UNUSED(par1); ARG_UNUSED(par1);
for (i = 0; i < par2; i++) { for (i = 0; i < par2; i++) {
nano_fiber_sem_take_wait(&nanoSem1); nano_fiber_sem_take_wait(&nanoSem1);
nano_fiber_sem_give(&nanoSem2); nano_fiber_sem_give(&nanoSem2);
}
} }
}
/******************************************************************************* /*******************************************************************************
* *
* sema_fiber2 - semaphore test context * sema_fiber2 - semaphore test context
* *
* @param par1 Address of the counter.
* @param par2 Number of test cycles.
*
* RETURNS: N/A * RETURNS: N/A
* *
* \NOMANUAL * \NOMANUAL
*/ */
void sema_fiber2( void sema_fiber2(int par1, int par2)
int par1, /* address of the counter */ {
int par2 /* number of test cycles */
)
{
int i; int i;
int * pcounter = (int *) par1; int * pcounter = (int *) par1;
for (i = 0; i < par2; i++) { for (i = 0; i < par2; i++) {
nano_fiber_sem_give(&nanoSem1); nano_fiber_sem_give(&nanoSem1);
nano_fiber_sem_take_wait(&nanoSem2); nano_fiber_sem_take_wait(&nanoSem2);
(*pcounter)++; (*pcounter)++;
}
} }
}
/******************************************************************************* /*******************************************************************************
* *
* sema_fiber3 - semaphore test context * sema_fiber3 - semaphore test context
* *
* @param par1 Address of the counter.
* @param par2 Number of test cycles.
*
* RETURNS: N/A * RETURNS: N/A
* *
* \NOMANUAL * \NOMANUAL
*/ */
void sema_fiber3( void sema_fiber3(int par1, int par2)
int par1, /* address of the counter */ {
int par2 /* number of test cycles */
)
{
int i; int i;
int * pcounter = (int *) par1; int * pcounter = (int *) par1;
for (i = 0; i < par2; i++) { for (i = 0; i < par2; i++) {
nano_fiber_sem_give(&nanoSem1); nano_fiber_sem_give(&nanoSem1);
while (!nano_fiber_sem_take(&nanoSem2)) while (!nano_fiber_sem_take(&nanoSem2)) {
fiber_yield(); fiber_yield();
(*pcounter)++; }
} (*pcounter)++;
} }
}
/******************************************************************************* /*******************************************************************************
@ -136,16 +137,16 @@ void sema_fiber3(
*/ */
int sema_test(void) int sema_test(void)
{ {
uint32_t t; uint32_t t;
int i = 0; int i = 0;
int return_value = 0; int return_value = 0;
fprintf(output_file, sz_test_case_fmt, fprintf(output_file, sz_test_case_fmt,
"Semaphore channel - 'nano_fiber_sem_take_wait'"); "Semaphore channel - 'nano_fiber_sem_take_wait'");
fprintf(output_file, sz_description, fprintf(output_file, sz_description,
"testing 'nano_sem_init','nano_fiber_sem_take_wait'," "testing 'nano_sem_init','nano_fiber_sem_take_wait',"
" 'nano_fiber_sem_give' functions;"); " 'nano_fiber_sem_give' functions;");
printf(sz_test_start_fmt, "'nano_fiber_sem_take_wait'"); printf(sz_test_start_fmt, "'nano_fiber_sem_take_wait'");
sema_test_init(); sema_test_init();
@ -153,18 +154,18 @@ int sema_test(void)
t = BENCH_START(); t = BENCH_START();
task_fiber_start(fiber_stack1, STACK_SIZE, sema_fiber1, 0, task_fiber_start(fiber_stack1, STACK_SIZE, sema_fiber1, 0,
NUMBER_OF_LOOPS, 3, 0); NUMBER_OF_LOOPS, 3, 0);
task_fiber_start(fiber_stack2, STACK_SIZE, sema_fiber2, (int) &i, task_fiber_start(fiber_stack2, STACK_SIZE, sema_fiber2, (int) &i,
NUMBER_OF_LOOPS, 3, 0); NUMBER_OF_LOOPS, 3, 0);
t = TIME_STAMP_DELTA_GET(t); t = TIME_STAMP_DELTA_GET(t);
return_value += check_result(i, t); return_value += check_result(i, t);
fprintf(output_file, sz_test_case_fmt, fprintf(output_file, sz_test_case_fmt,
"Semaphore channel - 'nano_fiber_sem_take'"); "Semaphore channel - 'nano_fiber_sem_take'");
fprintf(output_file, sz_description, fprintf(output_file, sz_description,
"testing 'nano_sem_init','nano_fiber_sem_take', 'fiber_yield',\n"); "testing 'nano_sem_init','nano_fiber_sem_take', 'fiber_yield',\n");
fprintf(output_file, "\t'nano_fiber_sem_give' functions;"); fprintf(output_file, "\t'nano_fiber_sem_give' functions;");
printf(sz_test_start_fmt, "'nano_fiber_sem_take'"); printf(sz_test_start_fmt, "'nano_fiber_sem_take'");
@ -174,21 +175,21 @@ int sema_test(void)
t = BENCH_START(); t = BENCH_START();
task_fiber_start(fiber_stack1, STACK_SIZE, sema_fiber1, 0, task_fiber_start(fiber_stack1, STACK_SIZE, sema_fiber1, 0,
NUMBER_OF_LOOPS, 3, 0); NUMBER_OF_LOOPS, 3, 0);
task_fiber_start(fiber_stack2, STACK_SIZE, sema_fiber3, (int) &i, task_fiber_start(fiber_stack2, STACK_SIZE, sema_fiber3, (int) &i,
NUMBER_OF_LOOPS, 3, 0); NUMBER_OF_LOOPS, 3, 0);
t = TIME_STAMP_DELTA_GET(t); t = TIME_STAMP_DELTA_GET(t);
return_value += check_result(i, t); return_value += check_result(i, t);
fprintf(output_file, sz_test_case_fmt, fprintf(output_file, sz_test_case_fmt,
"Semaphore channel - 'nano_task_sem_take_wait'"); "Semaphore channel - 'nano_task_sem_take_wait'");
fprintf(output_file, sz_description, fprintf(output_file, sz_description,
"testing 'nano_sem_init','nano_fiber_sem_take_wait'," "testing 'nano_sem_init','nano_fiber_sem_take_wait',"
" 'nano_fiber_sem_give',\n"); " 'nano_fiber_sem_give',\n");
fprintf(output_file, fprintf(output_file,
"\t'nano_task_sem_give', 'nano_task_sem_take_wait' functions;"); "\t'nano_task_sem_give', 'nano_task_sem_take_wait' functions;");
printf(sz_test_start_fmt, "'nano_task_sem_take_wait'"); printf(sz_test_start_fmt, "'nano_task_sem_take_wait'");
sema_test_init(); sema_test_init();
@ -196,10 +197,10 @@ int sema_test(void)
t = BENCH_START(); t = BENCH_START();
task_fiber_start(fiber_stack1, STACK_SIZE, sema_fiber1, 0, task_fiber_start(fiber_stack1, STACK_SIZE, sema_fiber1, 0,
NUMBER_OF_LOOPS, 3, 0); NUMBER_OF_LOOPS, 3, 0);
for (i = 0; i < NUMBER_OF_LOOPS; i++) { for (i = 0; i < NUMBER_OF_LOOPS; i++) {
nano_task_sem_give(&nanoSem1); nano_task_sem_give(&nanoSem1);
nano_task_sem_take_wait(&nanoSem2); nano_task_sem_take_wait(&nanoSem2);
} }
t = TIME_STAMP_DELTA_GET(t); t = TIME_STAMP_DELTA_GET(t);
@ -207,4 +208,4 @@ int sema_test(void)
return_value += check_result(i, t); return_value += check_result(i, t);
return return_value; return return_value;
} }

View file

@ -48,104 +48,109 @@ uint32_t stack2[2];
*/ */
void stack_test_init(void) void stack_test_init(void)
{ {
nano_stack_init(&nanoChannel1, stack1); nano_stack_init(&nanoChannel1, stack1);
nano_stack_init(&nanoChannel2, stack2); nano_stack_init(&nanoChannel2, stack2);
} }
/******************************************************************************* /*******************************************************************************
* *
* stack_fiber1 - stack test context * stack_fiber1 - stack test context
* *
* @param par1 Ignored parameter.
* @param par2 Number of test loops.
*
* RETURNS: N/A * RETURNS: N/A
* *
* \NOMANUAL * \NOMANUAL
*/ */
void stack_fiber1( void stack_fiber1(int par1, int par2)
int par1, /* ignored parameter */ {
int par2 /* number of test loops */
)
{
int i; int i;
uint32_t data; uint32_t data;
ARG_UNUSED(par1); ARG_UNUSED(par1);
for (i = 0; i < par2 / 2; i++) { for (i = 0; i < par2 / 2; i++) {
data = nano_fiber_stack_pop_wait(&nanoChannel1); data = nano_fiber_stack_pop_wait(&nanoChannel1);
if (data != 2 * i) if (data != 2 * i) {
break; break;
data = 2 * i; }
nano_fiber_stack_push(&nanoChannel2, data); data = 2 * i;
data = nano_fiber_stack_pop_wait(&nanoChannel1); nano_fiber_stack_push(&nanoChannel2, data);
if (data != 2 * i + 1) data = nano_fiber_stack_pop_wait(&nanoChannel1);
break; if (data != 2 * i + 1) {
data = 2 * i + 1; break;
nano_fiber_stack_push(&nanoChannel2, data); }
} data = 2 * i + 1;
nano_fiber_stack_push(&nanoChannel2, data);
} }
}
/******************************************************************************* /*******************************************************************************
* *
* stack_fiber2 - stack test context * stack_fiber2 - stack test context
* *
* @param par1 Address of the counter.
* @param par2 Number of test cycles.
*
* RETURNS: N/A * RETURNS: N/A
* *
* \NOMANUAL * \NOMANUAL
*/ */
void stack_fiber2( void stack_fiber2(int par1, int par2)
int par1, /* address of the counter */ {
int par2 /* number of test cycles */
)
{
int i; int i;
uint32_t data; uint32_t data;
int * pcounter = (int *) par1; int * pcounter = (int *) par1;
for (i = 0; i < par2; i++) { for (i = 0; i < par2; i++) {
data = i; data = i;
nano_fiber_stack_push(&nanoChannel1, data); nano_fiber_stack_push(&nanoChannel1, data);
data = nano_fiber_stack_pop_wait(&nanoChannel2); data = nano_fiber_stack_pop_wait(&nanoChannel2);
if (data != i) if (data != i) {
break; break;
(*pcounter)++; }
} (*pcounter)++;
} }
}
/******************************************************************************* /*******************************************************************************
* *
* stack_fiber2 - stack test context * stack_fiber2 - stack test context
* *
* @param par1 Address of the counter.
* @param par2 Number of test cycles.
*
* RETURNS: N/A * RETURNS: N/A
* *
* \NOMANUAL * \NOMANUAL
*/ */
void stack_fiber3( void stack_fiber3(int par1, int par2)
int par1, /* address of the counter */ {
int par2 /* number of test cycles */
)
{
int i; int i;
uint32_t data; uint32_t data;
int * pcounter = (int *) par1; int * pcounter = (int *) par1;
for (i = 0; i < par2; i++) { for (i = 0; i < par2; i++) {
data = i; data = i;
nano_fiber_stack_push(&nanoChannel1, data); nano_fiber_stack_push(&nanoChannel1, data);
data = 0xffffffff; data = 0xffffffff;
while (!nano_fiber_stack_pop(&nanoChannel2, &data)) while (!nano_fiber_stack_pop(&nanoChannel2, &data)) {
fiber_yield(); fiber_yield();
if (data != i) }
break; if (data != i) {
(*pcounter)++; break;
} }
(*pcounter)++;
} }
}
/******************************************************************************* /*******************************************************************************
@ -158,17 +163,17 @@ void stack_fiber3(
*/ */
int stack_test(void) int stack_test(void)
{ {
uint32_t t; uint32_t t;
int i = 0; int i = 0;
int return_value = 0; int return_value = 0;
/* test get wait & put fiber functions */ /* test get wait & put fiber functions */
fprintf(output_file, sz_test_case_fmt, fprintf(output_file, sz_test_case_fmt,
"Stack channel - 'nano_fiber_stack_pop_wait'"); "Stack channel - 'nano_fiber_stack_pop_wait'");
fprintf(output_file, sz_description, fprintf(output_file, sz_description,
"testing 'nano_stack_init','nano_fiber_stack_pop_wait'," "testing 'nano_stack_init','nano_fiber_stack_pop_wait',"
" 'nano_fiber_stack_push' functions;"); " 'nano_fiber_stack_push' functions;");
printf(sz_test_start_fmt, "'nano_fiber_stack_pop_wait'"); printf(sz_test_start_fmt, "'nano_fiber_stack_pop_wait'");
stack_test_init(); stack_test_init();
@ -176,22 +181,22 @@ int stack_test(void)
t = BENCH_START(); t = BENCH_START();
task_fiber_start(fiber_stack1, STACK_SIZE, stack_fiber1, 0, task_fiber_start(fiber_stack1, STACK_SIZE, stack_fiber1, 0,
NUMBER_OF_LOOPS, 3, 0); NUMBER_OF_LOOPS, 3, 0);
task_fiber_start(fiber_stack2, STACK_SIZE, stack_fiber2, (int) &i, task_fiber_start(fiber_stack2, STACK_SIZE, stack_fiber2, (int) &i,
NUMBER_OF_LOOPS, 3, 0); NUMBER_OF_LOOPS, 3, 0);
t = TIME_STAMP_DELTA_GET(t); t = TIME_STAMP_DELTA_GET(t);
return_value += check_result(i, t); return_value += check_result(i, t);
/* test get/yield & put fiber functions */ /* test get/yield & put fiber functions */
fprintf(output_file, sz_test_case_fmt, fprintf(output_file, sz_test_case_fmt,
"Stack channel - 'nano_fiber_stack_pop'"); "Stack channel - 'nano_fiber_stack_pop'");
fprintf(output_file, sz_description, fprintf(output_file, sz_description,
"testing 'nano_stack_init','nano_fiber_stack_pop_wait'," "testing 'nano_stack_init','nano_fiber_stack_pop_wait',"
" 'nano_fiber_stack_pop',\n"); " 'nano_fiber_stack_pop',\n");
fprintf(output_file, fprintf(output_file,
"\t'nano_fiber_stack_push', 'fiber_yield' functions;"); "\t'nano_fiber_stack_push', 'fiber_yield' functions;");
printf(sz_test_start_fmt, "'nano_fiber_stack_pop'"); printf(sz_test_start_fmt, "'nano_fiber_stack_pop'");
stack_test_init(); stack_test_init();
@ -200,22 +205,22 @@ int stack_test(void)
i = 0; i = 0;
task_fiber_start(fiber_stack1, STACK_SIZE, stack_fiber1, 0, task_fiber_start(fiber_stack1, STACK_SIZE, stack_fiber1, 0,
NUMBER_OF_LOOPS, 3, 0); NUMBER_OF_LOOPS, 3, 0);
task_fiber_start(fiber_stack2, STACK_SIZE, stack_fiber3, (int) &i, task_fiber_start(fiber_stack2, STACK_SIZE, stack_fiber3, (int) &i,
NUMBER_OF_LOOPS, 3, 0); NUMBER_OF_LOOPS, 3, 0);
t = TIME_STAMP_DELTA_GET(t); t = TIME_STAMP_DELTA_GET(t);
return_value += check_result(i, t); return_value += check_result(i, t);
/* test get wait & put fiber/task functions */ /* test get wait & put fiber/task functions */
fprintf(output_file, sz_test_case_fmt, fprintf(output_file, sz_test_case_fmt,
"Stack channel - 'nano_task_stack_pop_wait'"); "Stack channel - 'nano_task_stack_pop_wait'");
fprintf(output_file, sz_description, fprintf(output_file, sz_description,
"testing 'nano_stack_init','nano_fiber_stack_pop_wait'," "testing 'nano_stack_init','nano_fiber_stack_pop_wait',"
" 'nano_fiber_stack_push',\n"); " 'nano_fiber_stack_push',\n");
fprintf(output_file, fprintf(output_file,
"\t'nano_task_stack_pop_wait', 'nano_task_stack_push' functions;"); "\t'nano_task_stack_pop_wait', 'nano_task_stack_push' functions;");
printf(sz_test_start_fmt, "'nano_task_stack_pop_wait'"); printf(sz_test_start_fmt, "'nano_task_stack_pop_wait'");
stack_test_init(); stack_test_init();
@ -223,20 +228,22 @@ int stack_test(void)
t = BENCH_START(); t = BENCH_START();
task_fiber_start(fiber_stack1, STACK_SIZE, stack_fiber1, 0, task_fiber_start(fiber_stack1, STACK_SIZE, stack_fiber1, 0,
NUMBER_OF_LOOPS, 3, 0); NUMBER_OF_LOOPS, 3, 0);
for (i = 0; i < NUMBER_OF_LOOPS / 2; i++) { for (i = 0; i < NUMBER_OF_LOOPS / 2; i++) {
uint32_t data; uint32_t data;
data = 2 * i; data = 2 * i;
nano_task_stack_push(&nanoChannel1, data); nano_task_stack_push(&nanoChannel1, data);
data = 2 * i + 1; data = 2 * i + 1;
nano_task_stack_push(&nanoChannel1, data); nano_task_stack_push(&nanoChannel1, data);
data = nano_task_stack_pop_wait(&nanoChannel2); data = nano_task_stack_pop_wait(&nanoChannel2);
if (data != 2 * i + 1) if (data != 2 * i + 1) {
break; break;
data = nano_task_stack_pop_wait(&nanoChannel2); }
if (data != 2 * i) data = nano_task_stack_pop_wait(&nanoChannel2);
break; if (data != 2 * i) {
break;
}
} }
t = TIME_STAMP_DELTA_GET(t); t = TIME_STAMP_DELTA_GET(t);
@ -244,4 +251,4 @@ int stack_test(void)
return_value += check_result(i * 2, t); return_value += check_result(i * 2, t);
return return_value; return return_value;
} }

View file

@ -87,13 +87,13 @@ uint32_t tm_off;
* \NOMANUAL * \NOMANUAL
*/ */
void begin_test(void) void begin_test(void)
{ {
/* /*
Invoke bench_test_start in order to be able to use * Invoke bench_test_start in order to be able to use
tCheck static variable. * tCheck static variable.
*/ */
bench_test_start(); bench_test_start();
} }
/******************************************************************************* /*******************************************************************************
* *
@ -101,41 +101,41 @@ void begin_test(void)
* *
* RETURNS: 1 if success and 0 on failure * RETURNS: 1 if success and 0 on failure
* *
* @param i Number of tests.
* @param t Time in ticks for the whole test.
*
* \NOMANUAL * \NOMANUAL
*/ */
int check_result( int check_result(int i, uint32_t t)
int i, /* number of tests */ {
uint32_t t /* time in ticks for the whole test */ /*
) * bench_test_end checks tCheck static variable.
{ * bench_test_start modifies it
/* */
bench_test_end checks tCheck static variable.
bench_test_start modifies it
*/
if (bench_test_end() != 0) { if (bench_test_end() != 0) {
fprintf(output_file, sz_case_result_fmt, sz_fail); fprintf(output_file, sz_case_result_fmt, sz_fail);
fprintf(output_file, sz_case_details_fmt, fprintf(output_file, sz_case_details_fmt,
"timer tick happened. Results are inaccurate"); "timer tick happened. Results are inaccurate");
fprintf(output_file, sz_case_end_fmt); fprintf(output_file, sz_case_end_fmt);
return 0; return 0;
} }
if (i != NUMBER_OF_LOOPS) { if (i != NUMBER_OF_LOOPS) {
fprintf(output_file, sz_case_result_fmt, sz_fail); fprintf(output_file, sz_case_result_fmt, sz_fail);
fprintf(output_file, sz_case_details_fmt, "loop counter = "); fprintf(output_file, sz_case_details_fmt, "loop counter = ");
fprintf(output_file, "%i !!!", i); fprintf(output_file, "%i !!!", i);
fprintf(output_file, sz_case_end_fmt); fprintf(output_file, sz_case_end_fmt);
return 0; return 0;
} }
fprintf(output_file, sz_case_result_fmt, sz_success); fprintf(output_file, sz_case_result_fmt, sz_success);
fprintf(output_file, sz_case_details_fmt, fprintf(output_file, sz_case_details_fmt,
"Average time for 1 iteration: "); "Average time for 1 iteration: ");
fprintf(output_file, sz_case_timing_fmt, fprintf(output_file, sz_case_timing_fmt,
SYS_CLOCK_HW_CYCLES_TO_NS_AVG(t, NUMBER_OF_LOOPS)); SYS_CLOCK_HW_CYCLES_TO_NS_AVG(t, NUMBER_OF_LOOPS));
fprintf(output_file, sz_case_end_fmt); fprintf(output_file, sz_case_end_fmt);
return 1; return 1;
} }
/******************************************************************************* /*******************************************************************************
@ -159,20 +159,20 @@ int kbhit(void)
* *
* RETURNS: N/A * RETURNS: N/A
* *
* @param continuously Run test till the user presses the key.
*
* \NOMANUAL * \NOMANUAL
*/ */
void init_output( void init_output(int *continuously)
int *continuously /* run test till the user presses the key */ {
)
{
ARG_UNUSED(continuously); ARG_UNUSED(continuously);
/* /*
* send all printf and fprintf to console * send all printf and fprintf to console
*/ */
output_file = stdout; output_file = stdout;
} }
/******************************************************************************* /*******************************************************************************
@ -185,8 +185,8 @@ void init_output(
*/ */
void output_close(void) void output_close(void)
{ {
} }
/******************************************************************************* /*******************************************************************************
* *
@ -202,7 +202,7 @@ void SysKernelBench(void)
#else #else
void main(void) void main(void)
#endif #endif
{ {
int continuously = 0; int continuously = 0;
int test_result; int test_result;
@ -210,31 +210,33 @@ void main(void)
bench_test_init(); bench_test_init();
do { do {
fprintf(output_file, sz_module_title_fmt, "Nanokernel API test"); fprintf(output_file, sz_module_title_fmt, "Nanokernel API test");
fprintf(output_file, sz_kernel_ver_fmt, kernel_version_get()); fprintf(output_file, sz_kernel_ver_fmt, kernel_version_get());
fprintf(output_file, fprintf(output_file,
"\n\nEach test below are repeated %d times and the average\n" "\n\nEach test below are repeated %d times and the average\n"
"time for one iteration is displayed.", NUMBER_OF_LOOPS); "time for one iteration is displayed.", NUMBER_OF_LOOPS);
test_result = 0; test_result = 0;
test_result += sema_test(); test_result += sema_test();
test_result += lifo_test(); test_result += lifo_test();
test_result += fifo_test(); test_result += fifo_test();
test_result += stack_test(); test_result += stack_test();
if (test_result) { if (test_result) {
/* sema, lifo, fifo, stack account for twelve tests in total */ /* sema, lifo, fifo, stack account for twelve tests in total */
if (test_result == 12) if (test_result == 12) {
fprintf(output_file, sz_module_result_fmt, sz_success); fprintf(output_file, sz_module_result_fmt, sz_success);
else }
fprintf(output_file, sz_module_result_fmt, sz_partial); else {
} fprintf(output_file, sz_module_result_fmt, sz_partial);
else }
fprintf(output_file, sz_module_result_fmt, sz_fail); }
else {
fprintf(output_file, sz_module_result_fmt, sz_fail);
}
} } while (continuously && !kbhit());
while (continuously && !kbhit());
output_close(); output_close();
} }

View file

@ -74,12 +74,12 @@ int stack_test(void);
void begin_test(void); void begin_test(void);
static inline uint32_t BENCH_START(void) static inline uint32_t BENCH_START(void)
{ {
uint32_t et; uint32_t et;
begin_test(); begin_test();
et = TIME_STAMP_DELTA_GET(0); et = TIME_STAMP_DELTA_GET(0);
return et; return et;
} }
#endif /* SYSKERNEK_H */ #endif /* SYSKERNEK_H */

View file

@ -59,11 +59,11 @@ struct nano_sem sem[3];
*/ */
void isr0(void) void isr0(void)
{ {
printk("%s ran!\n", __FUNCTION__); printk("%s ran!\n", __FUNCTION__);
nano_isr_sem_give(&sem[0]); nano_isr_sem_give(&sem[0]);
_IntExit(); _IntExit();
} }
/******************************************************************************* /*******************************************************************************
* *
@ -73,11 +73,11 @@ void isr0(void)
*/ */
void isr1(void) void isr1(void)
{ {
printk("%s ran!\n", __FUNCTION__); printk("%s ran!\n", __FUNCTION__);
nano_isr_sem_give(&sem[1]); nano_isr_sem_give(&sem[1]);
_IntExit(); _IntExit();
} }
/******************************************************************************* /*******************************************************************************
* *
@ -87,11 +87,11 @@ void isr1(void)
*/ */
void isr2(void) void isr2(void)
{ {
printk("%s ran!\n", __FUNCTION__); printk("%s ran!\n", __FUNCTION__);
nano_isr_sem_give(&sem[2]); nano_isr_sem_give(&sem[2]);
_IntExit(); _IntExit();
} }
/******************************************************************************* /*******************************************************************************
* *
@ -101,13 +101,13 @@ void isr2(void)
*/ */
void main(void) void main(void)
{ {
TC_START("Test Cortex-M3 IRQ installed directly in vector table"); TC_START("Test Cortex-M3 IRQ installed directly in vector table");
for (int ii = 0; ii < 3; ii++) { for (int ii = 0; ii < 3; ii++) {
irq_enable(ii); irq_enable(ii);
irq_priority_set(ii, _EXC_IRQ_DEFAULT_PRIO); irq_priority_set(ii, _EXC_IRQ_DEFAULT_PRIO);
nano_sem_init(&sem[ii]); nano_sem_init(&sem[ii]);
} }
int rv; int rv;
@ -115,11 +115,13 @@ void main(void)
nano_task_sem_take(&sem[1]) || nano_task_sem_take(&sem[1]) ||
nano_task_sem_take(&sem[2]) ? TC_FAIL : TC_PASS; nano_task_sem_take(&sem[2]) ? TC_FAIL : TC_PASS;
if (TC_FAIL == rv) if (TC_FAIL == rv) {
goto get_out; goto get_out;
}
for (int ii = 0; ii < 3; ii++) for (int ii = 0; ii < 3; ii++) {
_NvicSwInterruptTrigger(ii); _NvicSwInterruptTrigger(ii);
}
rv = nano_task_sem_take(&sem[0]) && rv = nano_task_sem_take(&sem[0]) &&
nano_task_sem_take(&sem[1]) && nano_task_sem_take(&sem[1]) &&
@ -128,7 +130,7 @@ void main(void)
get_out: get_out:
TC_END_RESULT(rv); TC_END_RESULT(rv);
TC_END_REPORT(rv); TC_END_REPORT(rv);
} }
typedef void (*vth)(void); /* Vector Table Handler */ typedef void (*vth)(void); /* Vector Table Handler */
vth __irq_vector_table _irq_vector_table[CONFIG_NUM_IRQS] = { vth __irq_vector_table _irq_vector_table[CONFIG_NUM_IRQS] = {

View file

@ -96,9 +96,8 @@ typedef struct {
union { union {
void *data; /* pointer to data to use or return */ void *data; /* pointer to data to use or return */
int value; /* value to be passed or returned */ int value; /* value to be passed or returned */
}; };
} } ISR_INFO;
ISR_INFO;
typedef int (* disable_interrupt_func)(int); typedef int (* disable_interrupt_func)(int);
typedef void (* enable_interrupt_func)(int); typedef void (* enable_interrupt_func)(int);
@ -139,18 +138,18 @@ void isr_handler(void *data)
ARG_UNUSED(data); ARG_UNUSED(data);
switch (isrInfo.command) { switch (isrInfo.command) {
case CTX_SELF_CMD: case CTX_SELF_CMD:
isrInfo.data = (void *) context_self_get(); isrInfo.data = (void *) context_self_get();
break; break;
case CTX_TYPE_CMD: case CTX_TYPE_CMD:
isrInfo.value = context_type_get(); isrInfo.value = context_type_get();
break; break;
default: default:
isrInfo.error = UNKNOWN_COMMAND; isrInfo.error = UNKNOWN_COMMAND;
break; break;
} }
} }
/* Cortex-M3 does not implement connecting non-IRQ exception handlers */ /* Cortex-M3 does not implement connecting non-IRQ exception handlers */
@ -220,19 +219,19 @@ int nano_cpu_idleTest(void)
int tick; /* current tick count */ int tick; /* current tick count */
int i; /* loop variable */ int i; /* loop variable */
/* Align to a "tick boundary". */ /* Align to a "tick boundary". */
tick = nano_tick_get_32(); tick = nano_tick_get_32();
while (tick == nano_tick_get_32()) { while (tick == nano_tick_get_32()) {
} }
tick = nano_tick_get_32(); tick = nano_tick_get_32();
for (i = 0; i < 5; i++) { /* Repeat the test five times */ for (i = 0; i < 5; i++) { /* Repeat the test five times */
nano_cpu_idle(); nano_cpu_idle();
tick++; tick++;
if (nano_tick_get_32() != tick) { if (nano_tick_get_32() != tick) {
return TC_FAIL; return TC_FAIL;
}
} }
}
return TC_PASS; return TC_PASS;
} }
@ -334,22 +333,22 @@ int nanoCpuDisableInterruptsTest(disable_interrupt_func disableRtn,
int tick2; int tick2;
int imask; int imask;
/* Align to a "tick boundary" */ /* Align to a "tick boundary" */
tick = nano_tick_get_32(); tick = nano_tick_get_32();
while (nano_tick_get_32() == tick) { while (nano_tick_get_32() == tick) {
} }
tick++; tick++;
while (nano_tick_get_32() == tick) { while (nano_tick_get_32() == tick) {
count++; count++;
} }
/* /*
* Inflate <count> so that when we loop later, many ticks should have * Inflate <count> so that when we loop later, many ticks should have
* elapsed during the loop. This later loop will not exactly match the * elapsed during the loop. This later loop will not exactly match the
* previous loop, but it should be close enough in structure that when * previous loop, but it should be close enough in structure that when
* combined with the inflated count, many ticks will have passed. * combined with the inflated count, many ticks will have passed.
*/ */
count <<= 4; count <<= 4;
@ -357,25 +356,25 @@ int nanoCpuDisableInterruptsTest(disable_interrupt_func disableRtn,
tick = nano_tick_get_32(); tick = nano_tick_get_32();
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
nano_tick_get_32(); nano_tick_get_32();
} }
tick2 = nano_tick_get_32(); tick2 = nano_tick_get_32();
/* /*
* Re-enable interrupts before returning (for both success and failure * Re-enable interrupts before returning (for both success and failure
* cases). * cases).
*/ */
enableRtn(imask); enableRtn(imask);
if (tick2 != tick) { if (tick2 != tick) {
return TC_FAIL; return TC_FAIL;
} }
/* Now repeat with interrupts unlocked. */ /* Now repeat with interrupts unlocked. */
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
nano_tick_get_32(); nano_tick_get_32();
} }
return (tick == nano_tick_get_32()) ? TC_FAIL : TC_PASS; return (tick == nano_tick_get_32()) ? TC_FAIL : TC_PASS;
} }
@ -401,12 +400,12 @@ int nanoCtxTaskTest(void)
isrInfo.error = 0; isrInfo.error = 0;
_trigger_isrHandler(); _trigger_isrHandler();
if ((isrInfo.error != 0) || (isrInfo.data != (void *) ctxId)) { if ((isrInfo.error != 0) || (isrInfo.data != (void *) ctxId)) {
/* /*
* Either the ISR detected an error, or the ISR context ID does not * Either the ISR detected an error, or the ISR context ID does not
* match the interrupted task's context ID. * match the interrupted task's context ID.
*/ */
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT("Testing context_type_get() from an ISR\n"); TC_PRINT("Testing context_type_get() from an ISR\n");
isrInfo.command = CTX_TYPE_CMD; isrInfo.command = CTX_TYPE_CMD;
@ -414,12 +413,12 @@ int nanoCtxTaskTest(void)
_trigger_isrHandler(); _trigger_isrHandler();
if ((isrInfo.error != 0) || (isrInfo.value != NANO_CTX_ISR)) { if ((isrInfo.error != 0) || (isrInfo.value != NANO_CTX_ISR)) {
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT("Testing context_type_get() from a task\n"); TC_PRINT("Testing context_type_get() from a task\n");
if (context_type_get() != NANO_CTX_TASK) { if (context_type_get() != NANO_CTX_TASK) {
return TC_FAIL; return TC_FAIL;
} }
return TC_PASS; return TC_PASS;
} }
@ -449,19 +448,19 @@ int nanoCtxFiberTest(nano_context_id_t taskCtxId)
if (ctxId == taskCtxId) { if (ctxId == taskCtxId) {
fiberDetectedError = 1; fiberDetectedError = 1;
return TC_FAIL; return TC_FAIL;
} }
isrInfo.command = CTX_SELF_CMD; isrInfo.command = CTX_SELF_CMD;
isrInfo.error = 0; isrInfo.error = 0;
_trigger_isrHandler(); _trigger_isrHandler();
if ((isrInfo.error != 0) || (isrInfo.data != (void *) ctxId)) { if ((isrInfo.error != 0) || (isrInfo.data != (void *) ctxId)) {
/* /*
* Either the ISR detected an error, or the ISR context ID does not * Either the ISR detected an error, or the ISR context ID does not
* match the interrupted fiber's context ID. * match the interrupted fiber's context ID.
*/ */
fiberDetectedError = 2; fiberDetectedError = 2;
return TC_FAIL; return TC_FAIL;
} }
isrInfo.command = CTX_TYPE_CMD; isrInfo.command = CTX_TYPE_CMD;
isrInfo.error = 0; isrInfo.error = 0;
@ -469,12 +468,12 @@ int nanoCtxFiberTest(nano_context_id_t taskCtxId)
if ((isrInfo.error != 0) || (isrInfo.value != NANO_CTX_ISR)) { if ((isrInfo.error != 0) || (isrInfo.value != NANO_CTX_ISR)) {
fiberDetectedError = 3; fiberDetectedError = 3;
return TC_FAIL; return TC_FAIL;
} }
if (context_type_get() != NANO_CTX_FIBER) { if (context_type_get() != NANO_CTX_FIBER) {
fiberDetectedError = 4; fiberDetectedError = 4;
return TC_FAIL; return TC_FAIL;
} }
return TC_PASS; return TC_PASS;
} }
@ -499,20 +498,20 @@ static void fiberHelper(int arg1, int arg2)
ARG_UNUSED(arg1); ARG_UNUSED(arg1);
ARG_UNUSED(arg2); ARG_UNUSED(arg2);
/* /*
* This fiber starts off at a higher priority than fiberEntry(). Thus, it * This fiber starts off at a higher priority than fiberEntry(). Thus, it
* should execute immediately. * should execute immediately.
*/ */
fiberEvidence++; fiberEvidence++;
/* Test that helper will yield to a fiber of equal priority */ /* Test that helper will yield to a fiber of equal priority */
ctxId = context_self_get(); ctxId = context_self_get();
ctxId->prio++; /* Lower priority to that of fiberEntry() */ ctxId->prio++; /* Lower priority to that of fiberEntry() */
fiber_yield(); /* Yield to fiber of equal priority */ fiber_yield(); /* Yield to fiber of equal priority */
fiberEvidence++; fiberEvidence++;
/* <fiberEvidence> should now be 2 */ /* <fiberEvidence> should now be 2 */
} }
@ -538,27 +537,27 @@ int fiber_yieldTest(void)
{ {
nano_context_id_t ctxId; nano_context_id_t ctxId;
/* /*
* Start a fiber of higher priority. Note that since the new fiber is * Start a fiber of higher priority. Note that since the new fiber is
* being started from a fiber, it will not automatically switch to the * being started from a fiber, it will not automatically switch to the
* fiber as it would if done from a task. * fiber as it would if done from a task.
*/ */
ctxId = context_self_get(); ctxId = context_self_get();
fiberEvidence = 0; fiberEvidence = 0;
fiber_fiber_start(fiberStack2, FIBER_STACKSIZE, fiberHelper, fiber_fiber_start(fiberStack2, FIBER_STACKSIZE, fiberHelper,
0, 0, FIBER_PRIORITY - 1, 0); 0, 0, FIBER_PRIORITY - 1, 0);
if (fiberEvidence != 0) { if (fiberEvidence != 0) {
/* ERROR! Helper spawned at higher */ /* ERROR! Helper spawned at higher */
fiberDetectedError = 10; /* priority ran prematurely. */ fiberDetectedError = 10; /* priority ran prematurely. */
return TC_FAIL; return TC_FAIL;
} }
/* /*
* Test that the fiber will yield to the higher priority helper. * Test that the fiber will yield to the higher priority helper.
* <fiberEvidence> is still 0. * <fiberEvidence> is still 0.
*/ */
fiber_yield(); fiber_yield();
@ -566,18 +565,18 @@ int fiber_yieldTest(void)
/* ERROR! Did not yield to higher */ /* ERROR! Did not yield to higher */
fiberDetectedError = 11; /* priority fiber. */ fiberDetectedError = 11; /* priority fiber. */
return TC_FAIL; return TC_FAIL;
} }
if (fiberEvidence > 1) { if (fiberEvidence > 1) {
/* ERROR! Helper did not yield to */ /* ERROR! Helper did not yield to */
fiberDetectedError = 12; /* equal priority fiber. */ fiberDetectedError = 12; /* equal priority fiber. */
return TC_FAIL; return TC_FAIL;
} }
/* /*
* Raise the priority of fiberEntry(). Calling fiber_yield() should * Raise the priority of fiberEntry(). Calling fiber_yield() should
* not result in switching to the helper. * not result in switching to the helper.
*/ */
ctxId->prio--; ctxId->prio--;
fiber_yield(); fiber_yield();
@ -586,12 +585,12 @@ int fiber_yieldTest(void)
/* ERROR! Context switched to a lower */ /* ERROR! Context switched to a lower */
fiberDetectedError = 13; /* priority fiber! */ fiberDetectedError = 13; /* priority fiber! */
return TC_FAIL; return TC_FAIL;
} }
/* /*
* Block on <wakeFiber>. This will allow the helper fiber to complete. * Block on <wakeFiber>. This will allow the helper fiber to complete.
* The main task will wake this fiber. * The main task will wake this fiber.
*/ */
nano_fiber_sem_take_wait(&wakeFiber); nano_fiber_sem_take_wait(&wakeFiber);
@ -622,15 +621,15 @@ static void fiberEntry(int taskCtxId, int arg1)
rv = nanoCtxFiberTest((nano_context_id_t) taskCtxId); rv = nanoCtxFiberTest((nano_context_id_t) taskCtxId);
if (rv != TC_PASS) { if (rv != TC_PASS) {
return; return;
} }
/* Allow the task to print any messages before the next test runs */ /* Allow the task to print any messages before the next test runs */
nano_fiber_sem_take_wait(&wakeFiber); nano_fiber_sem_take_wait(&wakeFiber);
rv = fiber_yieldTest(); rv = fiber_yieldTest();
if (rv != TC_PASS) { if (rv != TC_PASS) {
return; return;
} }
} }
/******************************************************************************* /*******************************************************************************
@ -652,101 +651,101 @@ void main(void)
rv = initNanoObjects(); rv = initNanoObjects();
if (rv != TC_PASS) { if (rv != TC_PASS) {
goto doneTests; goto doneTests;
} }
TC_PRINT("Testing nano_cpu_idle()\n"); TC_PRINT("Testing nano_cpu_idle()\n");
rv = nano_cpu_idleTest(); rv = nano_cpu_idleTest();
if (rv != TC_PASS) { if (rv != TC_PASS) {
goto doneTests; goto doneTests;
} }
TC_PRINT("Testing interrupt locking and unlocking\n"); TC_PRINT("Testing interrupt locking and unlocking\n");
rv = nanoCpuDisableInterruptsTest(irq_lockWrapper, rv = nanoCpuDisableInterruptsTest(irq_lockWrapper,
irq_unlockWrapper, -1); irq_unlockWrapper, -1);
if (rv != TC_PASS) { if (rv != TC_PASS) {
goto doneTests; goto doneTests;
} }
TC_PRINT("Testing inline interrupt locking and unlocking\n"); TC_PRINT("Testing inline interrupt locking and unlocking\n");
rv = nanoCpuDisableInterruptsTest(irq_lock_inlineWrapper, rv = nanoCpuDisableInterruptsTest(irq_lock_inlineWrapper,
irq_unlock_inlineWrapper, -1); irq_unlock_inlineWrapper, -1);
if (rv != TC_PASS) { if (rv != TC_PASS) {
goto doneTests; goto doneTests;
} }
/* /*
* The Cortex-M3/M4 use the SYSTICK exception for the system timer, which is * The Cortex-M3/M4 use the SYSTICK exception for the system timer, which is
* not considered an IRQ by the irq_enable/Disable APIs. * not considered an IRQ by the irq_enable/Disable APIs.
*/ */
#if !defined(CONFIG_CPU_CORTEXM3) #if !defined(CONFIG_CPU_CORTEXM3)
/* /*
* !!! TAKE NOTE !!! * !!! TAKE NOTE !!!
* Disable interrupts coming from the timer. In the pcPentium case, this * Disable interrupts coming from the timer. In the pcPentium case, this
* is IRQ0 (see board.h for definition of PIT_INT_LVL). Other BSPs may * is IRQ0 (see board.h for definition of PIT_INT_LVL). Other BSPs may
* not be using the i8253 timer on IRQ0 and so a different IRQ value may * not be using the i8253 timer on IRQ0 and so a different IRQ value may
* be necessary when porting to another BSP. * be necessary when porting to another BSP.
*/ */
TC_PRINT("Testing irq_disable() and irq_enable()\n"); TC_PRINT("Testing irq_disable() and irq_enable()\n");
rv = nanoCpuDisableInterruptsTest(irq_disableWrapper, rv = nanoCpuDisableInterruptsTest(irq_disableWrapper,
irq_enableWrapper, TICK_IRQ); irq_enableWrapper, TICK_IRQ);
if (rv != TC_PASS) { if (rv != TC_PASS) {
goto doneTests; goto doneTests;
} }
#endif #endif
rv = nanoCtxTaskTest(); rv = nanoCtxTaskTest();
if (rv != TC_PASS) { if (rv != TC_PASS) {
goto doneTests; goto doneTests;
} }
TC_PRINT("Spawning a fiber from a task\n"); TC_PRINT("Spawning a fiber from a task\n");
fiberEvidence = 0; fiberEvidence = 0;
task_fiber_start(fiberStack1, FIBER_STACKSIZE, fiberEntry, task_fiber_start(fiberStack1, FIBER_STACKSIZE, fiberEntry,
(int) context_self_get(), 0, FIBER_PRIORITY, 0); (int) context_self_get(), 0, FIBER_PRIORITY, 0);
if (fiberEvidence != 1) { if (fiberEvidence != 1) {
rv = TC_FAIL; rv = TC_FAIL;
TC_ERROR(" - fiber did not execute as expected!\n"); TC_ERROR(" - fiber did not execute as expected!\n");
goto doneTests; goto doneTests;
} }
/* The fiber ran, now wake it so it can test context_self_get and context_type_get */ /* The fiber ran, now wake it so it can test context_self_get and context_type_get */
TC_PRINT("Fiber to test context_self_get() and context_type_get\n"); TC_PRINT("Fiber to test context_self_get() and context_type_get\n");
nano_task_sem_give(&wakeFiber); nano_task_sem_give(&wakeFiber);
if (fiberDetectedError != 0) { if (fiberDetectedError != 0) {
rv = TC_FAIL; rv = TC_FAIL;
TC_ERROR(" - failure detected in fiber; fiberDetectedError = %d\n", TC_ERROR(" - failure detected in fiber; fiberDetectedError = %d\n",
fiberDetectedError); fiberDetectedError);
goto doneTests; goto doneTests;
} }
TC_PRINT("Fiber to test fiber_yield()\n"); TC_PRINT("Fiber to test fiber_yield()\n");
nano_task_sem_give(&wakeFiber); nano_task_sem_give(&wakeFiber);
if (fiberDetectedError != 0) { if (fiberDetectedError != 0) {
rv = TC_FAIL; rv = TC_FAIL;
TC_ERROR(" - failure detected in fiber; fiberDetectedError = %d\n", TC_ERROR(" - failure detected in fiber; fiberDetectedError = %d\n",
fiberDetectedError); fiberDetectedError);
goto doneTests; goto doneTests;
} }
nano_task_sem_give(&wakeFiber); nano_task_sem_give(&wakeFiber);
/* Cortex-M3 does not implement connecting non-IRQ exception handlers */ /* Cortex-M3 does not implement connecting non-IRQ exception handlers */
#if !defined(CONFIG_CPU_CORTEXM3) #if !defined(CONFIG_CPU_CORTEXM3)
/* /*
* Test divide by zero exception handler. * Test divide by zero exception handler.
* *
* WARNING: This code has been very carefully crafted so that it does * WARNING: This code has been very carefully crafted so that it does
* what it is supposed to. Both "error" and "excHandlerExecuted" must be * what it is supposed to. Both "error" and "excHandlerExecuted" must be
* volatile to prevent the compiler from issuing a "divide by zero" * volatile to prevent the compiler from issuing a "divide by zero"
* warning (since otherwise in knows "excHandlerExecuted" is zero), * warning (since otherwise in knows "excHandlerExecuted" is zero),
* and to ensure the compiler issues the two byte "idiv" instruction * and to ensure the compiler issues the two byte "idiv" instruction
* that the exception handler is designed to deal with. * that the exception handler is designed to deal with.
*/ */
volatile int error; /* used to create a divide by zero error */ volatile int error; /* used to create a divide by zero error */
TC_PRINT("Verifying exception handler installed\n"); TC_PRINT("Verifying exception handler installed\n");

View file

@ -87,7 +87,7 @@ in ISR context.
typedef struct { typedef struct {
struct nano_fifo *channel; /* FIFO channel */ struct nano_fifo *channel; /* FIFO channel */
void *data; /* pointer to data to add */ void *data; /* pointer to data to add */
} ISR_FIFO_INFO; } ISR_FIFO_INFO;
/* globals */ /* globals */
@ -199,58 +199,58 @@ void fiber1(void)
void *pData; /* pointer to FIFO object get from the queue */ void *pData; /* pointer to FIFO object get from the queue */
int count = 0; /* counter */ int count = 0; /* counter */
/* Wait for fiber1 to be activated. */ /* Wait for fiber1 to be activated. */
nano_fiber_sem_take_wait(&nanoSemObj1); nano_fiber_sem_take_wait(&nanoSemObj1);
/* Wait for data to be added to <nanoFifoObj> by task */ /* Wait for data to be added to <nanoFifoObj> by task */
pData = nano_fiber_fifo_get_wait(&nanoFifoObj); pData = nano_fiber_fifo_get_wait(&nanoFifoObj);
if (pData != pPutList1[0]) { if (pData != pPutList1[0]) {
TC_ERROR("fiber1 (1) - expected 0x%x, got 0x%x\n", TC_ERROR("fiber1 (1) - expected 0x%x, got 0x%x\n",
pPutList1[0], pData); pPutList1[0], pData);
retCode = TC_FAIL; retCode = TC_FAIL;
return; return;
} }
/* Wait for data to be added to <nanoFifoObj2> by fiber3 */ /* Wait for data to be added to <nanoFifoObj2> by fiber3 */
pData = nano_fiber_fifo_get_wait(&nanoFifoObj2); pData = nano_fiber_fifo_get_wait(&nanoFifoObj2);
if (pData != pPutList2[0]) { if (pData != pPutList2[0]) {
TC_ERROR("fiber1 (2) - expected 0x%x, got 0x%x\n", TC_ERROR("fiber1 (2) - expected 0x%x, got 0x%x\n",
pPutList2[0], pData); pPutList2[0], pData);
retCode = TC_FAIL; retCode = TC_FAIL;
return; return;
} }
nano_fiber_sem_take_wait(&nanoSemObj1); /* Wait for fiber1 to be reactivated */ nano_fiber_sem_take_wait(&nanoSemObj1); /* Wait for fiber1 to be reactivated */
TC_PRINT("Test Fiber FIFO Get\n\n"); TC_PRINT("Test Fiber FIFO Get\n\n");
/* Get all FIFOs */ /* Get all FIFOs */
while ((pData = nano_fiber_fifo_get(&nanoFifoObj)) != NULL) { while ((pData = nano_fiber_fifo_get(&nanoFifoObj)) != NULL) {
TC_PRINT("FIBER FIFO Get: count = %d, ptr is %p\n", count, pData); TC_PRINT("FIBER FIFO Get: count = %d, ptr is %p\n", count, pData);
if((count >= NUM_FIFO_ELEMENT) || (pData != pPutList1[count])) { if ((count >= NUM_FIFO_ELEMENT) || (pData != pPutList1[count])) {
TCERR1(count); TCERR1(count);
retCode = TC_FAIL; retCode = TC_FAIL;
return; return;
}
count++;
} }
count++;
}
TC_END_RESULT(retCode); TC_END_RESULT(retCode);
PRINT_LINE; PRINT_LINE;
/* /*
* Entries in the FIFO queue have to be unique. * Entries in the FIFO queue have to be unique.
* Put data. * Put data.
*/ */
TC_PRINT("Test Fiber FIFO Put\n"); TC_PRINT("Test Fiber FIFO Put\n");
TC_PRINT("\nFIBER FIFO Put Order: "); TC_PRINT("\nFIBER FIFO Put Order: ");
for (int i=0; i<NUM_FIFO_ELEMENT; i++) { for (int i=0; i<NUM_FIFO_ELEMENT; i++) {
nano_fiber_fifo_put(&nanoFifoObj, pPutList2[i]); nano_fiber_fifo_put(&nanoFifoObj, pPutList2[i]);
TC_PRINT(" %p,", pPutList2[i]); TC_PRINT(" %p,", pPutList2[i]);
} }
TC_PRINT("\n"); TC_PRINT("\n");
PRINT_LINE; PRINT_LINE;
/* Give semaphore to allow the main task to run */ /* Give semaphore to allow the main task to run */
nano_fiber_sem_give(&nanoSemObjTask); nano_fiber_sem_give(&nanoSemObjTask);
} /* fiber1 */ } /* fiber1 */
@ -274,12 +274,12 @@ void testFiberFifoGetW(void)
TC_PRINT("Test Fiber FIFO Get Wait Interfaces\n\n"); TC_PRINT("Test Fiber FIFO Get Wait Interfaces\n\n");
pGetData = nano_fiber_fifo_get_wait(&nanoFifoObj2); pGetData = nano_fiber_fifo_get_wait(&nanoFifoObj2);
TC_PRINT("FIBER FIFO Get from queue2: %p\n", pGetData); TC_PRINT("FIBER FIFO Get from queue2: %p\n", pGetData);
/* Verify results */ /* Verify results */
if (pGetData != pMyFifoData1) { if (pGetData != pMyFifoData1) {
retCode = TC_FAIL; retCode = TC_FAIL;
TCERR2; TCERR2;
return; return;
} }
pPutData = pMyFifoData2; pPutData = pMyFifoData2;
TC_PRINT("FIBER FIFO Put to queue1: %p\n", pPutData); TC_PRINT("FIBER FIFO Put to queue1: %p\n", pPutData);
@ -287,12 +287,12 @@ void testFiberFifoGetW(void)
pGetData = nano_fiber_fifo_get_wait(&nanoFifoObj2); pGetData = nano_fiber_fifo_get_wait(&nanoFifoObj2);
TC_PRINT("FIBER FIFO Get from queue2: %p\n", pGetData); TC_PRINT("FIBER FIFO Get from queue2: %p\n", pGetData);
/* Verify results */ /* Verify results */
if (pGetData != pMyFifoData3) { if (pGetData != pMyFifoData3) {
retCode = TC_FAIL; retCode = TC_FAIL;
TCERR2; TCERR2;
return; return;
} }
pPutData = pMyFifoData4; pPutData = pMyFifoData4;
TC_PRINT("FIBER FIFO Put to queue1: %p\n", pPutData); TC_PRINT("FIBER FIFO Put to queue1: %p\n", pPutData);
@ -317,42 +317,42 @@ void testFiberFifoGetW(void)
void testIsrFifoFromFiber(void) void testIsrFifoFromFiber(void)
{ {
void *pGetData; /* pointer to FIFO object get from the queue */ void *pGetData; /* pointer to FIFO object get from the queue */
TC_PRINT("Test ISR FIFO (invoked from Fiber)\n\n"); TC_PRINT("Test ISR FIFO (invoked from Fiber)\n\n");
/* This is data pushed by function testFiberFifoGetW */ /* This is data pushed by function testFiberFifoGetW */
_trigger_nano_isr_fifo_get(); _trigger_nano_isr_fifo_get();
pGetData = isrFifoInfo.data; pGetData = isrFifoInfo.data;
TC_PRINT("ISR FIFO Get from queue1: %p\n", pGetData); TC_PRINT("ISR FIFO Get from queue1: %p\n", pGetData);
if (isrFifoInfo.data != pMyFifoData4) { if (isrFifoInfo.data != pMyFifoData4) {
retCode = TC_FAIL; retCode = TC_FAIL;
TCERR2; TCERR2;
return; return;
} }
/* Verify that the queue is empty */ /* Verify that the queue is empty */
_trigger_nano_isr_fifo_get(); _trigger_nano_isr_fifo_get();
pGetData = isrFifoInfo.data; pGetData = isrFifoInfo.data;
if (pGetData != NULL) { if (pGetData != NULL) {
TC_PRINT("Get from queue1: %p\n", pGetData); TC_PRINT("Get from queue1: %p\n", pGetData);
retCode = TC_FAIL; retCode = TC_FAIL;
TCERR3; TCERR3;
return; return;
} }
/* Put more item into queue */ /* Put more item into queue */
TC_PRINT("\nISR FIFO (running in fiber context) Put Order: \n"); TC_PRINT("\nISR FIFO (running in fiber context) Put Order: \n");
for (int i=0; i<NUM_FIFO_ELEMENT; i++) { for (int i=0; i<NUM_FIFO_ELEMENT; i++) {
isrFifoInfo.data = pPutList1[i]; isrFifoInfo.data = pPutList1[i];
TC_PRINT(" %p,", pPutList1[i]); TC_PRINT(" %p,", pPutList1[i]);
_trigger_nano_isr_fifo_put(); _trigger_nano_isr_fifo_put();
} }
TC_PRINT("\n"); TC_PRINT("\n");
TC_END_RESULT(retCode); TC_END_RESULT(retCode);
} /* testIsrFifoFromFiber */ } /* testIsrFifoFromFiber */
@ -371,54 +371,54 @@ void testIsrFifoFromFiber(void)
void testIsrFifoFromTask(void) void testIsrFifoFromTask(void)
{ {
void *pGetData; /* pointer to FIFO object get from the queue */ void *pGetData; /* pointer to FIFO object get from the queue */
void *pPutData; /* pointer to FIFO object put to queue */ void *pPutData; /* pointer to FIFO object put to queue */
int count = 0; /* counter */ int count = 0; /* counter */
TC_PRINT("Test ISR FIFO (invoked from Task)\n\n"); TC_PRINT("Test ISR FIFO (invoked from Task)\n\n");
/* This is data pushed by function testIsrFifoFromFiber /* This is data pushed by function testIsrFifoFromFiber
* Get all FIFOs * Get all FIFOs
*/ */
_trigger_nano_isr_fifo_get(); _trigger_nano_isr_fifo_get();
pGetData = isrFifoInfo.data; pGetData = isrFifoInfo.data;
while (pGetData != NULL) { while (pGetData != NULL) {
TC_PRINT("Get from queue1: count = %d, ptr is %p\n", count, pGetData); TC_PRINT("Get from queue1: count = %d, ptr is %p\n", count, pGetData);
if ((count >= NUM_FIFO_ELEMENT) || (pGetData != pPutList1[count])) { if ((count >= NUM_FIFO_ELEMENT) || (pGetData != pPutList1[count])) {
TCERR1(count); TCERR1(count);
retCode = TC_FAIL; retCode = TC_FAIL;
return; return;
}
/* Get the next element */
_trigger_nano_isr_fifo_get();
pGetData = isrFifoInfo.data;
count++;
} /* while */
/* Put data into queue and get it again */
pPutData = pPutList2[3];
isrFifoInfo.data = pPutData;
_trigger_nano_isr_fifo_put();
isrFifoInfo.data = NULL; /* force data to a new value */
/* Get data from queue */
_trigger_nano_isr_fifo_get();
pGetData = isrFifoInfo.data;
/* Verify data */
if (pGetData != pPutData) {
retCode = TC_FAIL;
TCERR2;
return;
} }
else {
/* Get the next element */
_trigger_nano_isr_fifo_get();
pGetData = isrFifoInfo.data;
count++;
} /* while */
/* Put data into queue and get it again */
pPutData = pPutList2[3];
isrFifoInfo.data = pPutData;
_trigger_nano_isr_fifo_put();
isrFifoInfo.data = NULL; /* force data to a new value */
/* Get data from queue */
_trigger_nano_isr_fifo_get();
pGetData = isrFifoInfo.data;
/* Verify data */
if (pGetData != pPutData) {
retCode = TC_FAIL;
TCERR2;
return;
}
else {
TC_PRINT("\nTest ISR FIFO (invoked from Task) - put %p and get back %p\n", TC_PRINT("\nTest ISR FIFO (invoked from Task) - put %p and get back %p\n",
pPutData, pGetData); pPutData, pGetData);
} }
TC_END_RESULT(retCode); TC_END_RESULT(retCode);
} /* testIsrFifoFromTask */ } /* testIsrFifoFromTask */
/******************************************************************************* /*******************************************************************************
@ -432,40 +432,40 @@ void fiber2(void)
{ {
void *pData; /* pointer to FIFO object from the queue */ void *pData; /* pointer to FIFO object from the queue */
/* Wait for fiber2 to be activated */ /* Wait for fiber2 to be activated */
nano_fiber_sem_take_wait(&nanoSemObj2); nano_fiber_sem_take_wait(&nanoSemObj2);
/* Wait for data to be added to <nanoFifoObj> */ /* Wait for data to be added to <nanoFifoObj> */
pData = nano_fiber_fifo_get_wait(&nanoFifoObj); pData = nano_fiber_fifo_get_wait(&nanoFifoObj);
if (pData != pPutList1[1]) { if (pData != pPutList1[1]) {
TC_ERROR("fiber2 (1) - expected 0x%x, got 0x%x\n", TC_ERROR("fiber2 (1) - expected 0x%x, got 0x%x\n",
pPutList1[1], pData); pPutList1[1], pData);
retCode = TC_FAIL; retCode = TC_FAIL;
return; return;
} }
/* Wait for data to be added to <nanoFifoObj2> by fiber3 */ /* Wait for data to be added to <nanoFifoObj2> by fiber3 */
pData = nano_fiber_fifo_get_wait(&nanoFifoObj2); pData = nano_fiber_fifo_get_wait(&nanoFifoObj2);
if (pData != pPutList2[1]) { if (pData != pPutList2[1]) {
TC_ERROR("fiber2 (2) - expected 0x%x, got 0x%x\n", TC_ERROR("fiber2 (2) - expected 0x%x, got 0x%x\n",
pPutList2[1], pData); pPutList2[1], pData);
retCode = TC_FAIL; retCode = TC_FAIL;
return; return;
} }
nano_fiber_sem_take_wait(&nanoSemObj2); /* Wait for fiber2 to be reactivated */ nano_fiber_sem_take_wait(&nanoSemObj2); /* Wait for fiber2 to be reactivated */
/* Fiber #2 has been reactivated by main task */ /* Fiber #2 has been reactivated by main task */
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
pData = nano_fiber_fifo_get_wait(&nanoFifoObj); pData = nano_fiber_fifo_get_wait(&nanoFifoObj);
if (pData != pPutList1[i]) { if (pData != pPutList1[i]) {
TC_ERROR("fiber2 (3) - iteration %d expected 0x%x, got 0x%x\n", TC_ERROR("fiber2 (3) - iteration %d expected 0x%x, got 0x%x\n",
i, pPutList1[i], pData); i, pPutList1[i], pData);
retCode = TC_FAIL; retCode = TC_FAIL;
return; return;
}
} }
}
nano_fiber_sem_give(&nanoSemObjTask); /* Wake main task */ nano_fiber_sem_give(&nanoSemObjTask); /* Wake main task */
nano_fiber_sem_take_wait(&nanoSemObj2); /* Wait for fiber2 to be reactivated */ nano_fiber_sem_take_wait(&nanoSemObj2); /* Wait for fiber2 to be reactivated */
@ -488,37 +488,37 @@ void fiber3(void)
{ {
void *pData; void *pData;
/* Wait for fiber3 to be activated */ /* Wait for fiber3 to be activated */
nano_fiber_sem_take_wait(&nanoSemObj3); nano_fiber_sem_take_wait(&nanoSemObj3);
/* Put two items onto <nanoFifoObj2> to unblock fibers #1 and #2. */ /* Put two items onto <nanoFifoObj2> to unblock fibers #1 and #2. */
nano_fiber_fifo_put(&nanoFifoObj2, pPutList2[0]); /* Wake fiber1 */ nano_fiber_fifo_put(&nanoFifoObj2, pPutList2[0]); /* Wake fiber1 */
nano_fiber_fifo_put(&nanoFifoObj2, pPutList2[1]); /* Wake fiber2 */ nano_fiber_fifo_put(&nanoFifoObj2, pPutList2[1]); /* Wake fiber2 */
/* Wait for fiber3 to be re-activated */ /* Wait for fiber3 to be re-activated */
nano_fiber_sem_take_wait(&nanoSemObj3); nano_fiber_sem_take_wait(&nanoSemObj3);
/* Immediately get the data from <nanoFifoObj2>. */ /* Immediately get the data from <nanoFifoObj2>. */
pData = nano_fiber_fifo_get_wait(&nanoFifoObj2); pData = nano_fiber_fifo_get_wait(&nanoFifoObj2);
if (pData != pPutList2[0]) { if (pData != pPutList2[0]) {
retCode = TC_FAIL; retCode = TC_FAIL;
TC_ERROR("fiber3 (1) - got 0x%x from <nanoFifoObj2>, expected 0x%x\n", TC_ERROR("fiber3 (1) - got 0x%x from <nanoFifoObj2>, expected 0x%x\n",
pData, pPutList2[0]); pData, pPutList2[0]);
} }
/* Put three items onto the FIFO for the task to get */ /* Put three items onto the FIFO for the task to get */
nano_fiber_fifo_put(&nanoFifoObj2, pPutList2[0]); nano_fiber_fifo_put(&nanoFifoObj2, pPutList2[0]);
nano_fiber_fifo_put(&nanoFifoObj2, pPutList2[1]); nano_fiber_fifo_put(&nanoFifoObj2, pPutList2[1]);
nano_fiber_fifo_put(&nanoFifoObj2, pPutList2[2]); nano_fiber_fifo_put(&nanoFifoObj2, pPutList2[2]);
/* Sleep for 2 seconds */ /* Sleep for 2 seconds */
nano_fiber_timer_start(&timer, SECONDS(2)); nano_fiber_timer_start(&timer, SECONDS(2));
nano_fiber_timer_wait(&timer); nano_fiber_timer_wait(&timer);
/* Put final item onto the FIFO for the task to get */ /* Put final item onto the FIFO for the task to get */
nano_fiber_fifo_put(&nanoFifoObj2, pPutList2[3]); nano_fiber_fifo_put(&nanoFifoObj2, pPutList2[3]);
/* Wait for fiber3 to be re-activated (not expected to occur) */ /* Wait for fiber3 to be re-activated (not expected to occur) */
nano_fiber_sem_take_wait(&nanoSemObj3); nano_fiber_sem_take_wait(&nanoSemObj3);
} }
@ -544,17 +544,17 @@ void testTaskFifoGetW(void)
TC_PRINT("TASK FIFO Put to queue2: %p\n", pPutData); TC_PRINT("TASK FIFO Put to queue2: %p\n", pPutData);
nano_task_fifo_put(&nanoFifoObj2, pPutData); nano_task_fifo_put(&nanoFifoObj2, pPutData);
/* Activate fiber2 */ /* Activate fiber2 */
nano_task_sem_give(&nanoSemObj2); nano_task_sem_give(&nanoSemObj2);
pGetData = nano_task_fifo_get_wait(&nanoFifoObj); pGetData = nano_task_fifo_get_wait(&nanoFifoObj);
TC_PRINT("TASK FIFO Get from queue1: %p\n", pGetData); TC_PRINT("TASK FIFO Get from queue1: %p\n", pGetData);
/* Verify results */ /* Verify results */
if (pGetData != pMyFifoData2) { if (pGetData != pMyFifoData2) {
retCode = TC_FAIL; retCode = TC_FAIL;
TCERR2; TCERR2;
return; return;
} }
pPutData = pMyFifoData3; pPutData = pMyFifoData3;
TC_PRINT("TASK FIFO Put to queue2: %p\n", pPutData); TC_PRINT("TASK FIFO Put to queue2: %p\n", pPutData);
@ -608,41 +608,41 @@ void main(void)
TC_START("Test Nanokernel FIFO"); TC_START("Test Nanokernel FIFO");
/* Initialize the FIFO queues and semaphore */ /* Initialize the FIFO queues and semaphore */
initNanoObjects(); initNanoObjects();
/* Create and start the three (3) fibers. */ /* Create and start the three (3) fibers. */
task_fiber_start(&fiberStack1[0], STACKSIZE, (nano_fiber_entry_t) fiber1, task_fiber_start(&fiberStack1[0], STACKSIZE, (nano_fiber_entry_t) fiber1,
0, 0, 7, 0); 0, 0, 7, 0);
task_fiber_start(&fiberStack2[0], STACKSIZE, (nano_fiber_entry_t) fiber2, task_fiber_start(&fiberStack2[0], STACKSIZE, (nano_fiber_entry_t) fiber2,
0, 0, 7, 0); 0, 0, 7, 0);
task_fiber_start(&fiberStack3[0], STACKSIZE, (nano_fiber_entry_t) fiber3, task_fiber_start(&fiberStack3[0], STACKSIZE, (nano_fiber_entry_t) fiber3,
0, 0, 7, 0); 0, 0, 7, 0);
/* /*
* The three fibers have each blocked on a different semaphore. Giving * The three fibers have each blocked on a different semaphore. Giving
* the semaphore nanoSemObjX will unblock fiberX (where X = {1, 2, 3}). * the semaphore nanoSemObjX will unblock fiberX (where X = {1, 2, 3}).
* *
* Activate fibers #1 and #2. They will each block on nanoFifoObj. * Activate fibers #1 and #2. They will each block on nanoFifoObj.
*/ */
nano_task_sem_give(&nanoSemObj1); nano_task_sem_give(&nanoSemObj1);
nano_task_sem_give(&nanoSemObj2); nano_task_sem_give(&nanoSemObj2);
/* Put two items into <nanoFifoObj> to unblock fibers #1 and #2. */ /* Put two items into <nanoFifoObj> to unblock fibers #1 and #2. */
nano_task_fifo_put(&nanoFifoObj, pPutList1[0]); /* Wake fiber1 */ nano_task_fifo_put(&nanoFifoObj, pPutList1[0]); /* Wake fiber1 */
nano_task_fifo_put(&nanoFifoObj, pPutList1[1]); /* Wake fiber2 */ nano_task_fifo_put(&nanoFifoObj, pPutList1[1]); /* Wake fiber2 */
/* Activate fiber #3 */ /* Activate fiber #3 */
nano_task_sem_give(&nanoSemObj3); nano_task_sem_give(&nanoSemObj3);
/* /*
* All three fibers should be blocked on their semaphores. Put data into * All three fibers should be blocked on their semaphores. Put data into
* <nanoFifoObj2>. Fiber #3 will read it after it is reactivated. * <nanoFifoObj2>. Fiber #3 will read it after it is reactivated.
*/ */
nano_task_fifo_put(&nanoFifoObj2, pPutList2[0]); nano_task_fifo_put(&nanoFifoObj2, pPutList2[0]);
nano_task_sem_give(&nanoSemObj3); /* Reactivate fiber #3 */ nano_task_sem_give(&nanoSemObj3); /* Reactivate fiber #3 */
@ -650,37 +650,37 @@ void main(void)
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
pData = nano_task_fifo_get_wait(&nanoFifoObj2); pData = nano_task_fifo_get_wait(&nanoFifoObj2);
if (pData != pPutList2[i]) { if (pData != pPutList2[i]) {
TC_ERROR("nano_task_fifo_get_wait() expected 0x%x, got 0x%x\n", TC_ERROR("nano_task_fifo_get_wait() expected 0x%x, got 0x%x\n",
pPutList2[i], pData); pPutList2[i], pData);
goto exit; goto exit;
}
} }
}
/* Add items to <nanoFifoObj> for fiber #2 */ /* Add items to <nanoFifoObj> for fiber #2 */
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
nano_task_fifo_put(&nanoFifoObj, pPutList1[i]); nano_task_fifo_put(&nanoFifoObj, pPutList1[i]);
} }
nano_task_sem_give(&nanoSemObj2); /* Activate fiber #2 */ nano_task_sem_give(&nanoSemObj2); /* Activate fiber #2 */
/* Wait for fibers to finish */ /* Wait for fibers to finish */
nano_task_sem_take_wait(&nanoSemObjTask); nano_task_sem_take_wait(&nanoSemObjTask);
if (retCode == TC_FAIL) { if (retCode == TC_FAIL) {
goto exit; goto exit;
} }
/* /*
* Entries in the FIFO queue have to be unique. * Entries in the FIFO queue have to be unique.
* Put data to queue. * Put data to queue.
*/ */
TC_PRINT("Test Task FIFO Put\n"); TC_PRINT("Test Task FIFO Put\n");
TC_PRINT("\nTASK FIFO Put Order: "); TC_PRINT("\nTASK FIFO Put Order: ");
for (int i=0; i<NUM_FIFO_ELEMENT; i++) { for (int i=0; i<NUM_FIFO_ELEMENT; i++) {
nano_task_fifo_put(&nanoFifoObj, pPutList1[i]); nano_task_fifo_put(&nanoFifoObj, pPutList1[i]);
TC_PRINT(" %p,", pPutList1[i]); TC_PRINT(" %p,", pPutList1[i]);
} }
TC_PRINT("\n"); TC_PRINT("\n");
PRINT_LINE; PRINT_LINE;
@ -689,28 +689,28 @@ void main(void)
if (retCode == TC_FAIL) { if (retCode == TC_FAIL) {
goto exit; goto exit;
} }
/* /*
* Wait for fiber1 to complete execution. (Using a semaphore gives * Wait for fiber1 to complete execution. (Using a semaphore gives
* the fiber the freedom to do blocking-type operations if it wants to.) * the fiber the freedom to do blocking-type operations if it wants to.)
*/ */
nano_task_sem_take_wait(&nanoSemObjTask); nano_task_sem_take_wait(&nanoSemObjTask);
TC_PRINT("Test Task FIFO Get\n"); TC_PRINT("Test Task FIFO Get\n");
/* Get all FIFOs */ /* Get all FIFOs */
while ((pData = nano_task_fifo_get(&nanoFifoObj)) != NULL) { while ((pData = nano_task_fifo_get(&nanoFifoObj)) != NULL) {
TC_PRINT("TASK FIFO Get: count = %d, ptr is %p\n", count, pData); TC_PRINT("TASK FIFO Get: count = %d, ptr is %p\n", count, pData);
if ((count >= NUM_FIFO_ELEMENT) || (pData != pPutList2[count])) { if ((count >= NUM_FIFO_ELEMENT) || (pData != pPutList2[count])) {
TCERR1(count); TCERR1(count);
retCode = TC_FAIL; retCode = TC_FAIL;
goto exit; goto exit;
}
count++;
} }
count++;
}
/* Test FIFO Get Wait interfaces*/ /* Test FIFO Get Wait interfaces*/
testTaskFifoGetW(); testTaskFifoGetW();
PRINT_LINE; PRINT_LINE;

View file

@ -73,12 +73,12 @@ These scenarios will be tested using a combinations of tasks, fibers and ISRs.
typedef struct { typedef struct {
struct nano_lifo *channel; /* LIFO channel */ struct nano_lifo *channel; /* LIFO channel */
void *data; /* pointer to data to add */ void *data; /* pointer to data to add */
} ISR_LIFO_INFO; } ISR_LIFO_INFO;
typedef struct { typedef struct {
uint32_t link; /* 32-bit word for LIFO to use as a link */ uint32_t link; /* 32-bit word for LIFO to use as a link */
uint32_t data; /* miscellaneous data put on LIFO (not important) */ uint32_t data; /* miscellaneous data put on LIFO (not important) */
} LIFO_ITEM; } LIFO_ITEM;
/* locals */ /* locals */
@ -160,10 +160,10 @@ int fiberLifoWaitTest(void)
{ {
void *data; /* ptr to data retrieved from LIFO */ void *data; /* ptr to data retrieved from LIFO */
/* /*
* The LIFO is empty; wait for an item to be added to the LIFO * The LIFO is empty; wait for an item to be added to the LIFO
* from the task. * from the task.
*/ */
TC_PRINT("Fiber waiting on an empty LIFO\n"); TC_PRINT("Fiber waiting on an empty LIFO\n");
nano_fiber_sem_give(&taskWaitSem); nano_fiber_sem_give(&taskWaitSem);
@ -171,35 +171,35 @@ int fiberLifoWaitTest(void)
if (data != &lifoItem[0]) { if (data != &lifoItem[0]) {
fiberDetectedFailure = 1; fiberDetectedFailure = 1;
return -1; return -1;
} }
nano_fiber_sem_take_wait(&fiberWaitSem); nano_fiber_sem_take_wait(&fiberWaitSem);
data = nano_fiber_lifo_get_wait(&lifoChannel); data = nano_fiber_lifo_get_wait(&lifoChannel);
if (data != &lifoItem[2]) { if (data != &lifoItem[2]) {
fiberDetectedFailure = 1; fiberDetectedFailure = 1;
return -1; return -1;
} }
/* /*
* Give the task some time to check the results. Ideally, this would * Give the task some time to check the results. Ideally, this would
* be waiting for a semaphore instead of a using a delay, but if the * be waiting for a semaphore instead of a using a delay, but if the
* main task wakes the fiber before it blocks on the LIFO, the fiber * main task wakes the fiber before it blocks on the LIFO, the fiber
* will add the item to the LIFO too soon. Obviously, a semaphore could * will add the item to the LIFO too soon. Obviously, a semaphore could
* not be given if the task is blocked on the LIFO; hence the delay. * not be given if the task is blocked on the LIFO; hence the delay.
*/ */
nano_fiber_timer_start(&timer, SECONDS(2)); nano_fiber_timer_start(&timer, SECONDS(2));
nano_fiber_timer_wait(&timer); nano_fiber_timer_wait(&timer);
/* The task is waiting on an empty LIFO. Wake it up. */ /* The task is waiting on an empty LIFO. Wake it up. */
nano_fiber_lifo_put(&lifoChannel, &lifoItem[3]); nano_fiber_lifo_put(&lifoChannel, &lifoItem[3]);
nano_fiber_lifo_put(&lifoChannel, &lifoItem[1]); nano_fiber_lifo_put(&lifoChannel, &lifoItem[1]);
/* /*
* Wait for the task to check the results. If the results pass, then the * Wait for the task to check the results. If the results pass, then the
* the task will wake the fiber. If the results do not pass, then the * the task will wake the fiber. If the results do not pass, then the
* fiber will wait forever. * fiber will wait forever.
*/ */
nano_fiber_sem_take_wait(&fiberWaitSem); nano_fiber_sem_take_wait(&fiberWaitSem);
@ -220,62 +220,62 @@ int fiberLifoNonWaitTest(void)
{ {
void *data; /* pointer to data retrieved from LIFO */ void *data; /* pointer to data retrieved from LIFO */
/* The LIFO has two items in it; retrieve them both */ /* The LIFO has two items in it; retrieve them both */
data = nano_fiber_lifo_get(&lifoChannel); data = nano_fiber_lifo_get(&lifoChannel);
if (data != (void *) &lifoItem[3]) { if (data != (void *) &lifoItem[3]) {
goto errorReturn; goto errorReturn;
} }
data = nano_fiber_lifo_get(&lifoChannel); data = nano_fiber_lifo_get(&lifoChannel);
if (data != (void *) &lifoItem[2]) { if (data != (void *) &lifoItem[2]) {
goto errorReturn; goto errorReturn;
} }
/* LIFO should be empty--verify. */ /* LIFO should be empty--verify. */
data = nano_fiber_lifo_get(&lifoChannel); data = nano_fiber_lifo_get(&lifoChannel);
if (data != NULL) { if (data != NULL) {
goto errorReturn; goto errorReturn;
} }
/* /*
* The LIFO is now empty. Add two items to the LIFO and then wait * The LIFO is now empty. Add two items to the LIFO and then wait
* for the semaphore so that the task can retrieve them. * for the semaphore so that the task can retrieve them.
*/ */
TC_PRINT("Task to get LIFO items without waiting\n"); TC_PRINT("Task to get LIFO items without waiting\n");
nano_fiber_lifo_put(&lifoChannel, &lifoItem[0]); nano_fiber_lifo_put(&lifoChannel, &lifoItem[0]);
nano_fiber_lifo_put(&lifoChannel, &lifoItem[1]); nano_fiber_lifo_put(&lifoChannel, &lifoItem[1]);
nano_fiber_sem_give(&taskWaitSem); /* Wake the task (if blocked) */ nano_fiber_sem_give(&taskWaitSem); /* Wake the task (if blocked) */
/* /*
* Wait for the task to get the items and then trigger an ISR to populate * Wait for the task to get the items and then trigger an ISR to populate
* the LIFO. * the LIFO.
*/ */
nano_fiber_sem_take_wait(&fiberWaitSem); nano_fiber_sem_take_wait(&fiberWaitSem);
/* /*
* The task retrieved the two items from the LIFO and then triggered * The task retrieved the two items from the LIFO and then triggered
* two interrupts to add two other items to the LIFO. The fiber will * two interrupts to add two other items to the LIFO. The fiber will
* now trigger two interrupts to read the two items. * now trigger two interrupts to read the two items.
*/ */
_trigger_nano_isr_lifo_get(); _trigger_nano_isr_lifo_get();
if (isrLifoInfo.data != &lifoItem[1]) { if (isrLifoInfo.data != &lifoItem[1]) {
goto errorReturn; goto errorReturn;
} }
_trigger_nano_isr_lifo_get(); _trigger_nano_isr_lifo_get();
if (isrLifoInfo.data != &lifoItem[3]) { if (isrLifoInfo.data != &lifoItem[3]) {
goto errorReturn; goto errorReturn;
} }
/* The LIFO should now be empty--verify */ /* The LIFO should now be empty--verify */
_trigger_nano_isr_lifo_get(); _trigger_nano_isr_lifo_get();
if (isrLifoInfo.data != NULL) { if (isrLifoInfo.data != NULL) {
goto errorReturn; goto errorReturn;
} }
return 0; return 0;
@ -308,7 +308,7 @@ static void fiberEntry(int arg1, int arg2)
if (rv == 0) { if (rv == 0) {
fiberLifoNonWaitTest(); fiberLifoNonWaitTest();
} }
} }
@ -327,45 +327,45 @@ int taskLifoWaitTest(void)
{ {
void *data; /* ptr to data retrieved from LIFO */ void *data; /* ptr to data retrieved from LIFO */
/* Wait on <taskWaitSem> in case fiber's print message blocked */ /* Wait on <taskWaitSem> in case fiber's print message blocked */
nano_fiber_sem_take_wait(&taskWaitSem); nano_fiber_sem_take_wait(&taskWaitSem);
/* The fiber is waiting on the LIFO. Wake it. */ /* The fiber is waiting on the LIFO. Wake it. */
nano_task_lifo_put(&lifoChannel, &lifoItem[0]); nano_task_lifo_put(&lifoChannel, &lifoItem[0]);
/* /*
* The fiber ran, but is now blocked on the semaphore. Add an item to the * The fiber ran, but is now blocked on the semaphore. Add an item to the
* LIFO before giving the semaphore that wakes the fiber so that we can * LIFO before giving the semaphore that wakes the fiber so that we can
* cover the path of nano_fiber_lifo_get_wait() not waiting on the LIFO. * cover the path of nano_fiber_lifo_get_wait() not waiting on the LIFO.
*/ */
nano_task_lifo_put(&lifoChannel, &lifoItem[2]); nano_task_lifo_put(&lifoChannel, &lifoItem[2]);
nano_task_sem_give(&fiberWaitSem); nano_task_sem_give(&fiberWaitSem);
/* Check that the fiber got the correct item (lifoItem[0]) */ /* Check that the fiber got the correct item (lifoItem[0]) */
if (fiberDetectedFailure) { if (fiberDetectedFailure) {
TC_ERROR(" *** nano_task_lifo_put()/nano_fiber_lifo_get_wait() failure\n"); TC_ERROR(" *** nano_task_lifo_put()/nano_fiber_lifo_get_wait() failure\n");
return TC_FAIL; return TC_FAIL;
} }
/* The LIFO is empty. This time the task will wait for the item. */ /* The LIFO is empty. This time the task will wait for the item. */
TC_PRINT("Task waiting on an empty LIFO\n"); TC_PRINT("Task waiting on an empty LIFO\n");
data = nano_task_lifo_get_wait(&lifoChannel); data = nano_task_lifo_get_wait(&lifoChannel);
if (data != (void *) &lifoItem[1]) { if (data != (void *) &lifoItem[1]) {
TC_ERROR(" *** nano_task_lifo_get_wait()/nano_fiber_lifo_put() failure\n"); TC_ERROR(" *** nano_task_lifo_get_wait()/nano_fiber_lifo_put() failure\n");
return TC_FAIL; return TC_FAIL;
} }
data = nano_task_lifo_get_wait(&lifoChannel); data = nano_task_lifo_get_wait(&lifoChannel);
if (data != (void *) &lifoItem[3]) { if (data != (void *) &lifoItem[3]) {
TC_ERROR(" *** nano_task_lifo_get_wait()/nano_fiber_lifo_put() failure\n"); TC_ERROR(" *** nano_task_lifo_get_wait()/nano_fiber_lifo_put() failure\n");
return TC_FAIL; return TC_FAIL;
} }
/* Waiting on an empty LIFO passed for both fiber and task. */ /* Waiting on an empty LIFO passed for both fiber and task. */
return TC_PASS; return TC_PASS;
} }
@ -384,51 +384,51 @@ int taskLifoNonWaitTest(void)
{ {
void *data; /* ptr to data retrieved from LIFO */ void *data; /* ptr to data retrieved from LIFO */
/* /*
* The fiber is presently waiting for <fiberWaitSem>. Populate the LIFO * The fiber is presently waiting for <fiberWaitSem>. Populate the LIFO
* before waking the fiber. * before waking the fiber.
*/ */
TC_PRINT("Fiber to get LIFO items without waiting\n"); TC_PRINT("Fiber to get LIFO items without waiting\n");
nano_task_lifo_put(&lifoChannel, &lifoItem[2]); nano_task_lifo_put(&lifoChannel, &lifoItem[2]);
nano_task_lifo_put(&lifoChannel, &lifoItem[3]); nano_task_lifo_put(&lifoChannel, &lifoItem[3]);
nano_task_sem_give(&fiberWaitSem); /* Wake the fiber */ nano_task_sem_give(&fiberWaitSem); /* Wake the fiber */
/* Check that fiber received the items correctly */ /* Check that fiber received the items correctly */
if (fiberDetectedFailure) { if (fiberDetectedFailure) {
TC_ERROR(" *** nano_task_lifo_put()/nano_fiber_lifo_get() failure\n"); TC_ERROR(" *** nano_task_lifo_put()/nano_fiber_lifo_get() failure\n");
return TC_FAIL; return TC_FAIL;
} }
/* Wait for the fiber to be ready */ /* Wait for the fiber to be ready */
nano_task_sem_take_wait(&taskWaitSem); nano_task_sem_take_wait(&taskWaitSem);
data = nano_task_lifo_get(&lifoChannel); data = nano_task_lifo_get(&lifoChannel);
if (data != (void *) &lifoItem[1]) { if (data != (void *) &lifoItem[1]) {
TC_ERROR(" *** nano_task_lifo_get()/nano_fiber_lifo_put() failure\n"); TC_ERROR(" *** nano_task_lifo_get()/nano_fiber_lifo_put() failure\n");
return TC_FAIL; return TC_FAIL;
} }
data = nano_task_lifo_get(&lifoChannel); data = nano_task_lifo_get(&lifoChannel);
if (data != (void *) &lifoItem[0]) { if (data != (void *) &lifoItem[0]) {
TC_ERROR(" *** nano_task_lifo_get()/nano_fiber_lifo_put() failure\n"); TC_ERROR(" *** nano_task_lifo_get()/nano_fiber_lifo_put() failure\n");
return TC_FAIL; return TC_FAIL;
} }
data = nano_task_lifo_get(&lifoChannel); data = nano_task_lifo_get(&lifoChannel);
if (data != NULL) { if (data != NULL) {
TC_ERROR(" *** nano_task_lifo_get()/nano_fiber_lifo_put() failure\n"); TC_ERROR(" *** nano_task_lifo_get()/nano_fiber_lifo_put() failure\n");
return TC_FAIL; return TC_FAIL;
} }
/* /*
* Software interrupts have been configured so that when invoked, * Software interrupts have been configured so that when invoked,
* the ISR will add an item to the LIFO. The fiber (when unblocked) * the ISR will add an item to the LIFO. The fiber (when unblocked)
* trigger software interrupts to get the items from the LIFO from * trigger software interrupts to get the items from the LIFO from
* within an ISR. * within an ISR.
* *
* Populate the LIFO. * Populate the LIFO.
*/ */
TC_PRINT("ISR to get LIFO items without waiting\n"); TC_PRINT("ISR to get LIFO items without waiting\n");
isrLifoInfo.data = &lifoItem[3]; isrLifoInfo.data = &lifoItem[3];
@ -443,7 +443,7 @@ int taskLifoNonWaitTest(void)
if (fiberDetectedFailure) { if (fiberDetectedFailure) {
TC_ERROR(" *** nano_isr_lifo_put()/nano_isr_lifo_get() failure\n"); TC_ERROR(" *** nano_isr_lifo_put()/nano_isr_lifo_get() failure\n");
return TC_FAIL; return TC_FAIL;
} }
return TC_PASS; return TC_PASS;
} }
@ -510,13 +510,13 @@ static void fiber_multi_waiters(int arg1, int arg2)
if (item != &multi_waiters_items[arg1]) { if (item != &multi_waiters_items[arg1]) {
TC_ERROR(" *** fiber %d did not receive correct item\n", arg1); TC_ERROR(" *** fiber %d did not receive correct item\n", arg1);
TC_ERROR(" *** received %p instead of %p.\n", TC_ERROR(" *** received %p instead of %p.\n",
item, &multi_waiters_items[arg1]); item, &multi_waiters_items[arg1]);
/* do NOT give the semaphore, signifying an error */ /* do NOT give the semaphore, signifying an error */
return; return;
} }
TC_PRINT("multiple-waiter fiber %d got correct item, giving semaphore\n", TC_PRINT("multiple-waiter fiber %d got correct item, giving semaphore\n",
arg1); arg1);
nano_fiber_sem_give(&reply_multi_waiters); nano_fiber_sem_give(&reply_multi_waiters);
} }
@ -534,7 +534,7 @@ static int do_test_multiple_waiters(void)
/* pend all fibers one the same lifo */ /* pend all fibers one the same lifo */
for (ii = 0; ii < NUM_WAITERS; ii++) { for (ii = 0; ii < NUM_WAITERS; ii++) {
task_fiber_start(fiber_multi_waiters_stacks[ii], FIBER_STACKSIZE, task_fiber_start(fiber_multi_waiters_stacks[ii], FIBER_STACKSIZE,
fiber_multi_waiters, ii, 0, FIBER_PRIORITY, 0); fiber_multi_waiters, ii, 0, FIBER_PRIORITY, 0);
} }
/* wake up all the fibers: the task is preempted each time */ /* wake up all the fibers: the task is preempted each time */
@ -551,7 +551,7 @@ static int do_test_multiple_waiters(void)
} }
TC_PRINT("Task took multi-waiter reply semaphore %d times, as expected.\n", TC_PRINT("Task took multi-waiter reply semaphore %d times, as expected.\n",
NUM_WAITERS); NUM_WAITERS);
if (nano_task_lifo_get(&multi_waiters)) { if (nano_task_lifo_get(&multi_waiters)) {
TC_ERROR(" *** multi_waiters should have been empty.\n"); TC_ERROR(" *** multi_waiters should have been empty.\n");
@ -607,23 +607,23 @@ void main(void)
initNanoObjects(); initNanoObjects();
/* /*
* Start the fiber. The fiber will be given a higher priority than the * Start the fiber. The fiber will be given a higher priority than the
* main task. * main task.
*/ */
task_fiber_start(fiberStack, FIBER_STACKSIZE, fiberEntry, task_fiber_start(fiberStack, FIBER_STACKSIZE, fiberEntry,
0, 0, FIBER_PRIORITY, 0); 0, 0, FIBER_PRIORITY, 0);
rv = taskLifoWaitTest(); rv = taskLifoWaitTest();
if (rv == TC_PASS) { if (rv == TC_PASS) {
rv = taskLifoNonWaitTest(); rv = taskLifoNonWaitTest();
} }
if (rv == TC_PASS) { if (rv == TC_PASS) {
rv = test_multiple_waiters(); rv = test_multiple_waiters();
} }
TC_END_RESULT(rv); TC_END_RESULT(rv);
TC_END_REPORT(rv); TC_END_REPORT(rv);

View file

@ -70,15 +70,15 @@ Scenario #3:
typedef struct { typedef struct {
struct nano_sem *sem; /* ptr to semaphore */ struct nano_sem *sem; /* ptr to semaphore */
int data; /* data */ int data; /* data */
} ISR_SEM_INFO; } ISR_SEM_INFO;
typedef enum { typedef enum {
STS_INIT = -1, STS_INIT = -1,
STS_TASK_WOKE_FIBER, STS_TASK_WOKE_FIBER,
STS_FIBER_WOKE_TASK, STS_FIBER_WOKE_TASK,
STS_ISR_WOKE_TASK STS_ISR_WOKE_TASK
} SEM_TEST_STATE; } SEM_TEST_STATE;
/* locals */ /* locals */
@ -153,26 +153,26 @@ int testSemFiberNoWait(void)
TC_PRINT("Giving and taking a semaphore in a fiber (non-blocking)\n"); TC_PRINT("Giving and taking a semaphore in a fiber (non-blocking)\n");
/* /*
* Give the semaphore many times and then make sure that it can only be * Give the semaphore many times and then make sure that it can only be
* taken that many times. * taken that many times.
*/ */
for (i = 0; i < 32; i++) { for (i = 0; i < 32; i++) {
nano_fiber_sem_give(&testSem); nano_fiber_sem_give(&testSem);
} }
for (i = 0; i < 32; i++) { for (i = 0; i < 32; i++) {
if (nano_fiber_sem_take(&testSem) != 1) { if (nano_fiber_sem_take(&testSem) != 1) {
TC_ERROR(" *** Expected nano_fiber_sem_take() to succeed, not fail\n"); TC_ERROR(" *** Expected nano_fiber_sem_take() to succeed, not fail\n");
goto errorReturn; goto errorReturn;
}
} }
}
if (nano_fiber_sem_take(&testSem) != 0) { if (nano_fiber_sem_take(&testSem) != 0) {
TC_ERROR(" *** Expected nano_fiber_sem_take() to fail, not succeed\n"); TC_ERROR(" *** Expected nano_fiber_sem_take() to fail, not succeed\n");
goto errorReturn; goto errorReturn;
} }
return TC_PASS; return TC_PASS;
@ -204,56 +204,57 @@ static void fiberEntry(int arg1, int arg2)
rv = testSemFiberNoWait(); rv = testSemFiberNoWait();
if (rv != TC_PASS) { if (rv != TC_PASS) {
return; return;
} }
/* /*
* At this point <testSem> is not available. Wait for <testSem> to become * At this point <testSem> is not available. Wait for <testSem> to become
* available (the main task will give it). * available (the main task will give it).
*/ */
nano_fiber_sem_take_wait(&testSem); nano_fiber_sem_take_wait(&testSem);
semTestState = STS_TASK_WOKE_FIBER; semTestState = STS_TASK_WOKE_FIBER;
/* /*
* Delay for two seconds. This gives the main task time to print * Delay for two seconds. This gives the main task time to print
* any messages (very important if I/O link is slow!), and wait * any messages (very important if I/O link is slow!), and wait
* on <testSem>. Once the delay is done, this fiber will give <testSem> * on <testSem>. Once the delay is done, this fiber will give <testSem>
* thus waking the main task. * thus waking the main task.
*/ */
nano_fiber_timer_start(&timer, SECONDS(2)); nano_fiber_timer_start(&timer, SECONDS(2));
nano_fiber_timer_wait(&timer); nano_fiber_timer_wait(&timer);
/* /*
* The main task is now waiting on <testSem>. Give the semaphore <testSem> * The main task is now waiting on <testSem>. Give the semaphore <testSem>
* to wake it. * to wake it.
*/ */
nano_fiber_sem_give(&testSem); nano_fiber_sem_give(&testSem);
/* /*
* Some small delay must be done so that the main task can process the * Some small delay must be done so that the main task can process the
* semaphore signal. * semaphore signal.
*/ */
semTestState = STS_FIBER_WOKE_TASK; semTestState = STS_FIBER_WOKE_TASK;
nano_fiber_timer_start(&timer, SECONDS(2)); nano_fiber_timer_start(&timer, SECONDS(2));
nano_fiber_timer_wait(&timer); nano_fiber_timer_wait(&timer);
/* /*
* The main task should be waiting on <testSem> again. This time, instead * The main task should be waiting on <testSem> again. This time, instead
* of giving the semaphore from the semaphore, give it from an ISR to wake * of giving the semaphore from the semaphore, give it from an ISR to wake
* the main task. * the main task.
*/ */
isrSemInfo.data = 0; isrSemInfo.data = 0;
isrSemInfo.sem = &testSem; isrSemInfo.sem = &testSem;
_trigger_nano_isr_sem_give(); _trigger_nano_isr_sem_give();
if (isrSemInfo.data == 1) if (isrSemInfo.data == 1) {
semTestState = STS_ISR_WOKE_TASK; semTestState = STS_ISR_WOKE_TASK;
}
} }
/******************************************************************************* /*******************************************************************************
@ -298,30 +299,30 @@ int testSemIsrNoWait(void)
TC_PRINT("Giving and taking a semaphore in an ISR (non-blocking)\n"); TC_PRINT("Giving and taking a semaphore in an ISR (non-blocking)\n");
/* /*
* Give the semaphore many times and then make sure that it can only be * Give the semaphore many times and then make sure that it can only be
* taken that many times. * taken that many times.
*/ */
isrSemInfo.sem = &testSem; isrSemInfo.sem = &testSem;
for (i = 0; i < 32; i++) { for (i = 0; i < 32; i++) {
_trigger_nano_isr_sem_give(); _trigger_nano_isr_sem_give();
} }
for (i = 0; i < 32; i++) { for (i = 0; i < 32; i++) {
isrSemInfo.data = 0; isrSemInfo.data = 0;
_trigger_nano_isr_sem_take(); _trigger_nano_isr_sem_take();
if (isrSemInfo.data != 1) { if (isrSemInfo.data != 1) {
TC_ERROR(" *** Expected nano_isr_sem_take() to succeed, not fail\n"); TC_ERROR(" *** Expected nano_isr_sem_take() to succeed, not fail\n");
goto errorReturn; goto errorReturn;
}
} }
}
_trigger_nano_isr_sem_take(); _trigger_nano_isr_sem_take();
if (isrSemInfo.data != 0) { if (isrSemInfo.data != 0) {
TC_ERROR(" *** Expected nano_isr_sem_take() to fail, not succeed!\n"); TC_ERROR(" *** Expected nano_isr_sem_take() to fail, not succeed!\n");
goto errorReturn; goto errorReturn;
} }
return TC_PASS; return TC_PASS;
@ -345,26 +346,26 @@ int testSemTaskNoWait(void)
TC_PRINT("Giving and taking a semaphore in a task (non-blocking)\n"); TC_PRINT("Giving and taking a semaphore in a task (non-blocking)\n");
/* /*
* Give the semaphore many times and then make sure that it can only be * Give the semaphore many times and then make sure that it can only be
* taken that many times. * taken that many times.
*/ */
for (i = 0; i < 32; i++) { for (i = 0; i < 32; i++) {
nano_task_sem_give(&testSem); nano_task_sem_give(&testSem);
} }
for (i = 0; i < 32; i++) { for (i = 0; i < 32; i++) {
if (nano_task_sem_take(&testSem) != 1) { if (nano_task_sem_take(&testSem) != 1) {
TC_ERROR(" *** Expected nano_task_sem_take() to succeed, not fail\n"); TC_ERROR(" *** Expected nano_task_sem_take() to succeed, not fail\n");
goto errorReturn; goto errorReturn;
}
} }
}
if (nano_task_sem_take(&testSem) != 0) { if (nano_task_sem_take(&testSem) != 0) {
TC_ERROR(" *** Expected nano_task_sem_take() to fail, not succeed!\n"); TC_ERROR(" *** Expected nano_task_sem_take() to fail, not succeed!\n");
goto errorReturn; goto errorReturn;
} }
return TC_PASS; return TC_PASS;
@ -387,14 +388,14 @@ int testSemWait(void)
if (fiberDetectedFailure != 0) { if (fiberDetectedFailure != 0) {
TC_ERROR(" *** Failure detected in the fiber."); TC_ERROR(" *** Failure detected in the fiber.");
return TC_FAIL; return TC_FAIL;
} }
nano_task_sem_give(&testSem); /* Wake the fiber. */ nano_task_sem_give(&testSem); /* Wake the fiber. */
if (semTestState != STS_TASK_WOKE_FIBER) { if (semTestState != STS_TASK_WOKE_FIBER) {
TC_ERROR(" *** Expected task to wake fiber. It did not.\n"); TC_ERROR(" *** Expected task to wake fiber. It did not.\n");
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT("Semaphore from the task woke the fiber\n"); TC_PRINT("Semaphore from the task woke the fiber\n");
@ -403,7 +404,7 @@ int testSemWait(void)
if (semTestState != STS_FIBER_WOKE_TASK) { if (semTestState != STS_FIBER_WOKE_TASK) {
TC_ERROR(" *** Expected fiber to wake task. It did not.\n"); TC_ERROR(" *** Expected fiber to wake task. It did not.\n");
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT("Semaphore from the fiber woke the task\n"); TC_PRINT("Semaphore from the fiber woke the task\n");
@ -412,7 +413,7 @@ int testSemWait(void)
if (semTestState != STS_ISR_WOKE_TASK) { if (semTestState != STS_ISR_WOKE_TASK) {
TC_ERROR(" *** Expected ISR to wake task. It did not.\n"); TC_ERROR(" *** Expected ISR to wake task. It did not.\n");
return TC_FAIL; return TC_FAIL;
} }
TC_PRINT("Semaphore from the ISR woke the task.\n"); TC_PRINT("Semaphore from the ISR woke the task.\n");
return TC_PASS; return TC_PASS;
@ -541,32 +542,32 @@ void main(void)
rv = testSemTaskNoWait(); rv = testSemTaskNoWait();
if (rv != TC_PASS) { if (rv != TC_PASS) {
goto doneTests; goto doneTests;
} }
rv = testSemIsrNoWait(); rv = testSemIsrNoWait();
if (rv != TC_PASS) { if (rv != TC_PASS) {
goto doneTests; goto doneTests;
} }
semTestState = STS_INIT; semTestState = STS_INIT;
/* /*
* Start the fiber. The fiber will be given a higher priority than the * Start the fiber. The fiber will be given a higher priority than the
* main task. * main task.
*/ */
task_fiber_start(fiberStack, FIBER_STACKSIZE, fiberEntry, task_fiber_start(fiberStack, FIBER_STACKSIZE, fiberEntry,
0, 0, FIBER_PRIORITY, 0); 0, 0, FIBER_PRIORITY, 0);
rv = testSemWait(); rv = testSemWait();
if (rv != TC_PASS) { if (rv != TC_PASS) {
goto doneTests; goto doneTests;
} }
rv = test_multiple_waiters(); rv = test_multiple_waiters();
if (rv != TC_PASS) { if (rv != TC_PASS) {
goto doneTests; goto doneTests;
} }
doneTests: doneTests:
TC_END_RESULT(rv); TC_END_RESULT(rv);

View file

@ -87,8 +87,8 @@ these are run in ISR context.
typedef struct { typedef struct {
struct nano_stack *channel; /* STACK channel */ struct nano_stack *channel; /* STACK channel */
uint32_t data; /* data to add */ uint32_t data; /* data to add */
} ISR_STACK_INFO; } ISR_STACK_INFO;
/* globals */ /* globals */
@ -100,9 +100,9 @@ char fiberStack3[STACKSIZE];
struct nano_timer timer; struct nano_timer timer;
struct nano_stack nanoStackObj; struct nano_stack nanoStackObj;
struct nano_stack nanoStackObj2; struct nano_stack nanoStackObj2;
struct nano_sem nanoSemObj; /* Used for transferring control between struct nano_sem nanoSemObj; /* Used for transferring control between
* main and fiber1 * main and fiber1
*/ */
uint32_t myData[NUM_STACK_ELEMENT]; uint32_t myData[NUM_STACK_ELEMENT];
uint32_t myIsrData[NUM_STACK_ELEMENT]; /* Data used for testing uint32_t myIsrData[NUM_STACK_ELEMENT]; /* Data used for testing
@ -151,7 +151,7 @@ void initData(void)
for (int i=0; i< NUM_STACK_ELEMENT; i++) { for (int i=0; i< NUM_STACK_ELEMENT; i++) {
myData[i] = (STARTNUM + i) * MULTIPLIER; myData[i] = (STARTNUM + i) * MULTIPLIER;
myIsrData[i] = myData[i] + MYNUMBER; myIsrData[i] = myData[i] + MYNUMBER;
} }
} /* initData */ } /* initData */
/******************************************************************************* /*******************************************************************************
@ -192,9 +192,9 @@ void isr_stack_pop(void *parameter)
ISR_STACK_INFO *pInfo = (ISR_STACK_INFO *) parameter; ISR_STACK_INFO *pInfo = (ISR_STACK_INFO *) parameter;
if (nano_isr_stack_pop(pInfo->channel, &(pInfo->data)) == 0) { if (nano_isr_stack_pop(pInfo->channel, &(pInfo->data)) == 0) {
/* the stack is empty, set data to INVALID_DATA */ /* the stack is empty, set data to INVALID_DATA */
pInfo->data = INVALID_DATA; pInfo->data = INVALID_DATA;
} }
} /* isr_stack_pop */ } /* isr_stack_pop */
@ -216,31 +216,31 @@ void fiber1(void)
int count = 0; /* counter */ int count = 0; /* counter */
TC_PRINT("Test Fiber STACK Pop\n\n"); TC_PRINT("Test Fiber STACK Pop\n\n");
/* Get all data */ /* Get all data */
while (nano_fiber_stack_pop(&nanoStackObj, &data) != 0) { while (nano_fiber_stack_pop(&nanoStackObj, &data) != 0) {
TC_PRINT("FIBER STACK Pop: count = %d, data is %d\n", count, data); TC_PRINT("FIBER STACK Pop: count = %d, data is %d\n", count, data);
if((count >= NUM_STACK_ELEMENT) || (data != myData[NUM_STACK_ELEMENT - 1 - count])) { if((count >= NUM_STACK_ELEMENT) || (data != myData[NUM_STACK_ELEMENT - 1 - count])) {
TCERR1(count); TCERR1(count);
retCode = TC_FAIL; retCode = TC_FAIL;
return; return;
}
count++;
} }
count++;
}
TC_END_RESULT(retCode); TC_END_RESULT(retCode);
PRINT_LINE; PRINT_LINE;
/* Put data */ /* Put data */
TC_PRINT("Test Fiber STACK Push\n"); TC_PRINT("Test Fiber STACK Push\n");
TC_PRINT("\nFIBER STACK Put Order: "); TC_PRINT("\nFIBER STACK Put Order: ");
for (int i=NUM_STACK_ELEMENT; i>0; i--) { for (int i=NUM_STACK_ELEMENT; i>0; i--) {
nano_fiber_stack_push(&nanoStackObj, myData[i-1]); nano_fiber_stack_push(&nanoStackObj, myData[i-1]);
TC_PRINT(" %d,", myData[i-1]); TC_PRINT(" %d,", myData[i-1]);
} }
TC_PRINT("\n"); TC_PRINT("\n");
PRINT_LINE; PRINT_LINE;
/* Give semaphore to allow the main task to run */ /* Give semaphore to allow the main task to run */
nano_fiber_sem_give(&nanoSemObj); nano_fiber_sem_give(&nanoSemObj);
} /* fiber1 */ } /* fiber1 */
@ -264,12 +264,12 @@ void testFiberStackPopW(void)
TC_PRINT("Test Fiber STACK Pop Wait Interfaces\n\n"); TC_PRINT("Test Fiber STACK Pop Wait Interfaces\n\n");
data = nano_fiber_stack_pop_wait(&nanoStackObj2); data = nano_fiber_stack_pop_wait(&nanoStackObj2);
TC_PRINT("FIBER STACK Pop from queue2: %d\n", data); TC_PRINT("FIBER STACK Pop from queue2: %d\n", data);
/* Verify results */ /* Verify results */
if (data != myData[0]) { if (data != myData[0]) {
retCode = TC_FAIL; retCode = TC_FAIL;
TCERR2; TCERR2;
return; return;
} }
data = myData[1]; data = myData[1];
TC_PRINT("FIBER STACK Push to queue1: %d\n", data); TC_PRINT("FIBER STACK Push to queue1: %d\n", data);
@ -277,12 +277,12 @@ void testFiberStackPopW(void)
data = nano_fiber_stack_pop_wait(&nanoStackObj2); data = nano_fiber_stack_pop_wait(&nanoStackObj2);
TC_PRINT("FIBER STACK Pop from queue2: %d\n", data); TC_PRINT("FIBER STACK Pop from queue2: %d\n", data);
/* Verify results */ /* Verify results */
if (data != myData[2]) { if (data != myData[2]) {
retCode = TC_FAIL; retCode = TC_FAIL;
TCERR2; TCERR2;
return; return;
} }
data = myData[3]; data = myData[3];
TC_PRINT("FIBER STACK Push to queue1: %d\n", data); TC_PRINT("FIBER STACK Push to queue1: %d\n", data);
@ -310,19 +310,19 @@ void testIsrStackFromFiber(void)
TC_PRINT("Test ISR STACK (invoked from Fiber)\n\n"); TC_PRINT("Test ISR STACK (invoked from Fiber)\n\n");
/* This is data pushed by function testFiberStackPopW */ /* This is data pushed by function testFiberStackPopW */
_trigger_nano_isr_stack_pop(); _trigger_nano_isr_stack_pop();
result = isrStackInfo.data; result = isrStackInfo.data;
if (result != INVALID_DATA) { if (result != INVALID_DATA) {
TC_PRINT("ISR STACK (running in fiber context) Pop from queue1: %d\n", result); TC_PRINT("ISR STACK (running in fiber context) Pop from queue1: %d\n", result);
if (result != myData[3]) { if (result != myData[3]) {
retCode = TC_FAIL; retCode = TC_FAIL;
TCERR2; TCERR2;
return; return;
}
} }
}
/* Verify that the STACK is empty */ /* Verify that the STACK is empty */
_trigger_nano_isr_stack_pop(); _trigger_nano_isr_stack_pop();
result = isrStackInfo.data; result = isrStackInfo.data;
if (result != INVALID_DATA) { if (result != INVALID_DATA) {
@ -330,19 +330,19 @@ void testIsrStackFromFiber(void)
retCode = TC_FAIL; retCode = TC_FAIL;
TCERR3; TCERR3;
return; return;
} }
/* Put more data into STACK */ /* Put more data into STACK */
TC_PRINT("ISR STACK (running in fiber context) Push to queue1: \n"); TC_PRINT("ISR STACK (running in fiber context) Push to queue1: \n");
for (int i=0; i<NUM_STACK_ELEMENT; i++) { for (int i=0; i<NUM_STACK_ELEMENT; i++) {
isrStackInfo.data = myIsrData[i]; isrStackInfo.data = myIsrData[i];
TC_PRINT(" %d, ", myIsrData[i]); TC_PRINT(" %d, ", myIsrData[i]);
_trigger_nano_isr_stack_push(); _trigger_nano_isr_stack_push();
} }
TC_PRINT("\n"); TC_PRINT("\n");
isrStackInfo.data = INVALID_DATA; /* Set variable to INVALID_DATA to ensure
* [data] changes /* Set variable to INVALID_DATA to ensure [data] changes */
*/ isrStackInfo.data = INVALID_DATA;
TC_END_RESULT(retCode); TC_END_RESULT(retCode);
@ -367,41 +367,41 @@ void testIsrStackFromTask(void)
TC_PRINT("Test ISR STACK (invoked from Task)\n\n"); TC_PRINT("Test ISR STACK (invoked from Task)\n\n");
/* Get all data */ /* Get all data */
_trigger_nano_isr_stack_pop(); _trigger_nano_isr_stack_pop();
result = isrStackInfo.data; result = isrStackInfo.data;
while (result != INVALID_DATA) { while (result != INVALID_DATA) {
TC_PRINT(" Pop from queue1: count = %d, data is %d\n", count, result); TC_PRINT(" Pop from queue1: count = %d, data is %d\n", count, result);
if ((count >= NUM_STACK_ELEMENT) || (result != myIsrData[NUM_STACK_ELEMENT - count - 1])) { if ((count >= NUM_STACK_ELEMENT) || (result != myIsrData[NUM_STACK_ELEMENT - count - 1])) {
TCERR1(count); TCERR1(count);
retCode = TC_FAIL; retCode = TC_FAIL;
return; return;
} /* if */ } /* if */
/* Get the next element */ /* Get the next element */
_trigger_nano_isr_stack_pop(); _trigger_nano_isr_stack_pop();
result = isrStackInfo.data; result = isrStackInfo.data;
count++; count++;
} /* while */ } /* while */
/* Put data into stack and get it again */ /* Put data into stack and get it again */
isrStackInfo.data = myIsrData[3]; isrStackInfo.data = myIsrData[3];
_trigger_nano_isr_stack_push(); _trigger_nano_isr_stack_push();
isrStackInfo.data = INVALID_DATA; /* force variable to a new value */ isrStackInfo.data = INVALID_DATA; /* force variable to a new value */
/* Get data from stack */ /* Get data from stack */
_trigger_nano_isr_stack_pop(); _trigger_nano_isr_stack_pop();
result = isrStackInfo.data; result = isrStackInfo.data;
/* Verify data */ /* Verify data */
if (result != myIsrData[3]) { if (result != myIsrData[3]) {
TCERR2; TCERR2;
retCode = TC_FAIL; retCode = TC_FAIL;
return; return;
} }
else { else {
TC_PRINT("\nTest ISR STACK (invoked from Task) - push %d and pop back %d\n", TC_PRINT("\nTest ISR STACK (invoked from Task) - push %d and pop back %d\n",
myIsrData[3], result); myIsrData[3], result);
} }
TC_END_RESULT(retCode); TC_END_RESULT(retCode);
@ -446,18 +446,18 @@ void testTaskStackPopW(void)
TC_PRINT("TASK STACK Push to queue2: %d\n", data); TC_PRINT("TASK STACK Push to queue2: %d\n", data);
nano_task_stack_push(&nanoStackObj2, data); nano_task_stack_push(&nanoStackObj2, data);
/* Start fiber */ /* Start fiber */
task_fiber_start(&fiberStack2[0], STACKSIZE, task_fiber_start(&fiberStack2[0], STACKSIZE,
(nano_fiber_entry_t) fiber2, 0, 0, 7, 0); (nano_fiber_entry_t) fiber2, 0, 0, 7, 0);
data = nano_task_stack_pop_wait(&nanoStackObj); data = nano_task_stack_pop_wait(&nanoStackObj);
TC_PRINT("TASK STACK Pop from queue1: %d\n", data); TC_PRINT("TASK STACK Pop from queue1: %d\n", data);
/* Verify results */ /* Verify results */
if (data != myData[1]) { if (data != myData[1]) {
retCode = TC_FAIL; retCode = TC_FAIL;
TCERR2; TCERR2;
return; return;
} }
data = myData[2]; data = myData[2];
TC_PRINT("TASK STACK Push to queue2: %d\n", data); TC_PRINT("TASK STACK Push to queue2: %d\n", data);
@ -523,77 +523,77 @@ void main(void)
TC_START("Test Nanokernel STACK"); TC_START("Test Nanokernel STACK");
/* Initialize data */ /* Initialize data */
initData(); initData();
/* Initialize the queues and semaphore */ /* Initialize the queues and semaphore */
initNanoObjects(); initNanoObjects();
/* Start fiber3 */ /* Start fiber3 */
task_fiber_start(&fiberStack3[0], STACKSIZE, (nano_fiber_entry_t) fiber3, task_fiber_start(&fiberStack3[0], STACKSIZE, (nano_fiber_entry_t) fiber3,
0, 0, 7, 0); 0, 0, 7, 0);
/* /*
* While fiber3 blocks (for one second), wait for an item to be pushed * While fiber3 blocks (for one second), wait for an item to be pushed
* onto the stack so that it can be popped. This will put the nanokernel * onto the stack so that it can be popped. This will put the nanokernel
* into an idle state. * into an idle state.
*/ */
data = nano_task_stack_pop_wait(&nanoStackObj); data = nano_task_stack_pop_wait(&nanoStackObj);
if (data != myData[0]) { if (data != myData[0]) {
TC_ERROR("nano_task_stack_pop_wait() expected 0x%x, but got 0x%x\n", TC_ERROR("nano_task_stack_pop_wait() expected 0x%x, but got 0x%x\n",
myData[0], data); myData[0], data);
retCode = TC_FAIL; retCode = TC_FAIL;
goto exit; goto exit;
} }
/* Put data */ /* Put data */
TC_PRINT("Test Task STACK Push\n"); TC_PRINT("Test Task STACK Push\n");
TC_PRINT("\nTASK STACK Put Order: "); TC_PRINT("\nTASK STACK Put Order: ");
for (int i=0; i<NUM_STACK_ELEMENT; i++) { for (int i=0; i<NUM_STACK_ELEMENT; i++) {
nano_task_stack_push(&nanoStackObj, myData[i]); nano_task_stack_push(&nanoStackObj, myData[i]);
TC_PRINT(" %d,", myData[i]); TC_PRINT(" %d,", myData[i]);
} }
TC_PRINT("\n"); TC_PRINT("\n");
PRINT_LINE; PRINT_LINE;
/* Start fiber */ /* Start fiber */
task_fiber_start(&fiberStack1[0], STACKSIZE, task_fiber_start(&fiberStack1[0], STACKSIZE,
(nano_fiber_entry_t) fiber1, 0, 0, 7, 0); (nano_fiber_entry_t) fiber1, 0, 0, 7, 0);
if (retCode == TC_FAIL) { if (retCode == TC_FAIL) {
goto exit; goto exit;
} }
/* /*
* Wait for fiber1 to complete execution. (Using a semaphore gives * Wait for fiber1 to complete execution. (Using a semaphore gives
* the fiber the freedom to do blocking-type operations if it wants to.) * the fiber the freedom to do blocking-type operations if it wants to.)
* *
*/ */
nano_task_sem_take_wait(&nanoSemObj); nano_task_sem_take_wait(&nanoSemObj);
TC_PRINT("Test Task STACK Pop\n"); TC_PRINT("Test Task STACK Pop\n");
/* Get all data */ /* Get all data */
while (nano_task_stack_pop(&nanoStackObj, &data) != 0) { while (nano_task_stack_pop(&nanoStackObj, &data) != 0) {
TC_PRINT("TASK STACK Pop: count = %d, data is %d\n", count, data); TC_PRINT("TASK STACK Pop: count = %d, data is %d\n", count, data);
if ((count >= NUM_STACK_ELEMENT) || (data != myData[count])) { if ((count >= NUM_STACK_ELEMENT) || (data != myData[count])) {
TCERR1(count); TCERR1(count);
retCode = TC_FAIL; retCode = TC_FAIL;
goto exit; goto exit;
}
count++;
} }
count++;
}
/* Test Task Stack Pop Wait interfaces*/ /* Test Task Stack Pop Wait interfaces*/
testTaskStackPopW(); testTaskStackPopW();
if (retCode == TC_FAIL) { if (retCode == TC_FAIL) {
goto exit; goto exit;
} }
PRINT_LINE; PRINT_LINE;
/* Test ISR interfaces */ /* Test ISR interfaces */
testIsrStackFromTask(); testIsrStackFromTask();
PRINT_LINE; PRINT_LINE;

View file

@ -144,8 +144,8 @@ int basicTimerWait(timer_start_func startRtn, timer_getw_func waitRtn,
tick = nano_tick_get_32(); tick = nano_tick_get_32();
while (nano_tick_get_32() == tick) { while (nano_tick_get_32() == tick) {
/* Align to a tick boundary */ /* Align to a tick boundary */
} }
tick++; tick++;
(void) nano_tick_delta(&reftime); (void) nano_tick_delta(&reftime);
@ -155,36 +155,36 @@ int basicTimerWait(timer_start_func startRtn, timer_getw_func waitRtn,
elapsed_32 = nano_tick_delta_32(&reftime); elapsed_32 = nano_tick_delta_32(&reftime);
duration = nano_tick_get_32() - tick; duration = nano_tick_get_32() - tick;
/* /*
* The difference between <duration> and <elapsed> is expected to be zero * The difference between <duration> and <elapsed> is expected to be zero
* however, the test is allowing for tolerance of an extra tick in case of * however, the test is allowing for tolerance of an extra tick in case of
* timing variations. * timing variations.
*/ */
if ((result != pTimerData) || if ((result != pTimerData) ||
(duration - elapsed_32 > 1) || ((duration - ticks) > 1)) { (duration - elapsed_32 > 1) || ((duration - ticks) > 1)) {
return TC_FAIL; return TC_FAIL;
} }
/* Check that the non-wait-timer-get routine works properly. */ /* Check that the non-wait-timer-get routine works properly. */
tick = nano_tick_get_32(); tick = nano_tick_get_32();
while (nano_tick_get_32() == tick) { while (nano_tick_get_32() == tick) {
/* Align to a tick boundary */ /* Align to a tick boundary */
} }
tick++; tick++;
(void) nano_tick_delta(&reftime); (void) nano_tick_delta(&reftime);
startRtn(pTimer, ticks); /* Start the timer */ startRtn(pTimer, ticks); /* Start the timer */
while ((result = getRtn(pTimer)) == NULL) { while ((result = getRtn(pTimer)) == NULL) {
busywaited = 1; busywaited = 1;
} }
elapsed = nano_tick_delta(&reftime); elapsed = nano_tick_delta(&reftime);
duration = nano_tick_get_32() - tick; duration = nano_tick_get_32() - tick;
if ((busywaited != 1) || (result != pTimerData) || if ((busywaited != 1) || (result != pTimerData) ||
(duration - elapsed > 1) || ((duration - ticks) > 1)) { (duration - elapsed > 1) || ((duration - ticks) > 1)) {
return TC_FAIL; return TC_FAIL;
} }
return TC_PASS; return TC_PASS;
} }
@ -212,8 +212,8 @@ void startTimers(timer_start_func startRtn)
tick = nano_tick_get_32(); tick = nano_tick_get_32();
while (nano_tick_get_32() == tick) { while (nano_tick_get_32() == tick) {
/* Wait for the end of the tick */ /* Wait for the end of the tick */
} }
startRtn(&timer, TWO_SECONDS); startRtn(&timer, TWO_SECONDS);
startRtn(&longTimer, LONG_TIMEOUT); startRtn(&longTimer, LONG_TIMEOUT);
@ -247,44 +247,44 @@ int busyWaitTimers(timer_get_func getRtn)
while ((numExpired != 4) && (nano_tick_get_32() < ticks)) { while ((numExpired != 4) && (nano_tick_get_32() < ticks)) {
result = getRtn(&timer); result = getRtn(&timer);
if (result != NULL) { if (result != NULL) {
numExpired++; numExpired++;
if ((result != timerData) || (numExpired != 2)) { if ((result != timerData) || (numExpired != 2)) {
TC_ERROR("Expected <timer> to expire 2nd, not 0x%x\n", TC_ERROR("Expected <timer> to expire 2nd, not 0x%x\n",
result); result);
return TC_FAIL; return TC_FAIL;
} }
} }
result = getRtn(&shortTimer); result = getRtn(&shortTimer);
if (result != NULL) { if (result != NULL) {
numExpired++; numExpired++;
if ((result != shortTimerData) || (numExpired != 1)) { if ((result != shortTimerData) || (numExpired != 1)) {
TC_ERROR("Expected <shortTimer> to expire 1st, not 0x%x\n", TC_ERROR("Expected <shortTimer> to expire 1st, not 0x%x\n",
result); result);
return TC_FAIL; return TC_FAIL;
} }
} }
result = getRtn(&midTimer); result = getRtn(&midTimer);
if (result != NULL) { if (result != NULL) {
numExpired++; numExpired++;
if ((result != midTimerData) || (numExpired != 3)) { if ((result != midTimerData) || (numExpired != 3)) {
TC_ERROR("Expected <midTimer> to expire 3rd, not 0x%x\n", TC_ERROR("Expected <midTimer> to expire 3rd, not 0x%x\n",
result); result);
return TC_FAIL; return TC_FAIL;
} }
} }
result = getRtn(&longTimer); result = getRtn(&longTimer);
if (result != NULL) { if (result != NULL) {
numExpired++; numExpired++;
if ((result != longTimerData) || (numExpired != 4)) { if ((result != longTimerData) || (numExpired != 4)) {
TC_ERROR("Expected <longTimer> to expire 4th, not 0x%x\n", TC_ERROR("Expected <longTimer> to expire 4th, not 0x%x\n",
result); result);
return TC_FAIL; return TC_FAIL;
} }
}
} }
}
return (nano_tick_get_32() < ticks) ? TC_PASS : TC_FAIL; return (nano_tick_get_32() < ticks) ? TC_PASS : TC_FAIL;
} }
@ -319,16 +319,16 @@ int stopTimers(timer_stop_func stopRtn, timer_get_func getRtn)
startTick = nano_tick_get_32(); startTick = nano_tick_get_32();
while (nano_tick_get_32() == startTick) { while (nano_tick_get_32() == startTick) {
} }
startTick++; startTick++;
endTick = startTick + SIX_SECONDS; endTick = startTick + SIX_SECONDS;
while (nano_tick_get_32() < endTick) { while (nano_tick_get_32() < endTick) {
if ((getRtn(&timer) != NULL) || (getRtn(&shortTimer) != NULL) || if ((getRtn(&timer) != NULL) || (getRtn(&shortTimer) != NULL) ||
(getRtn(&midTimer) != NULL) || (getRtn(&longTimer) != NULL)) { (getRtn(&midTimer) != NULL) || (getRtn(&longTimer) != NULL)) {
return TC_FAIL; return TC_FAIL;
}
} }
}
return TC_PASS; return TC_PASS;
} }
@ -378,16 +378,16 @@ static void fiberEntry(int arg1, int arg2)
TC_PRINT("Fiber testing basic timer functionality\n"); TC_PRINT("Fiber testing basic timer functionality\n");
rv = basicTimerWait(nano_fiber_timer_start, nano_fiber_timer_wait, rv = basicTimerWait(nano_fiber_timer_start, nano_fiber_timer_wait,
nano_fiber_timer_test, &timer, timerData, TWO_SECONDS); nano_fiber_timer_test, &timer, timerData, TWO_SECONDS);
nano_fiber_sem_give(&wakeTask); nano_fiber_sem_give(&wakeTask);
if (rv != TC_PASS) { if (rv != TC_PASS) {
fiberDetectedError = 1; fiberDetectedError = 1;
return; return;
} }
nano_fiber_sem_take_wait(&wakeFiber); /* Wait forever - let task run */ nano_fiber_sem_take_wait(&wakeFiber); /* Wait forever - let task run */
/* Check that timers expire in the correct order */ /* Check that timers expire in the correct order */
TC_PRINT("Fiber testing timers expire in the correct order\n"); TC_PRINT("Fiber testing timers expire in the correct order\n");
startTimers(nano_fiber_timer_start); startTimers(nano_fiber_timer_start);
rv = busyWaitTimers(nano_fiber_timer_test); rv = busyWaitTimers(nano_fiber_timer_test);
@ -395,10 +395,10 @@ static void fiberEntry(int arg1, int arg2)
if (rv != TC_PASS) { if (rv != TC_PASS) {
fiberDetectedError = 2; fiberDetectedError = 2;
return; return;
} }
nano_fiber_sem_take_wait(&wakeFiber); /* Wait forever - let task run */ nano_fiber_sem_take_wait(&wakeFiber); /* Wait forever - let task run */
/* Check that timers can be stopped */ /* Check that timers can be stopped */
TC_PRINT("Task testing the stopping of timers\n"); TC_PRINT("Task testing the stopping of timers\n");
startTimers(nano_fiber_timer_start); startTimers(nano_fiber_timer_start);
rv = stopTimers(nano_fiber_timer_stop, nano_fiber_timer_test); rv = stopTimers(nano_fiber_timer_stop, nano_fiber_timer_test);
@ -406,23 +406,23 @@ static void fiberEntry(int arg1, int arg2)
if (rv != TC_PASS) { if (rv != TC_PASS) {
fiberDetectedError = 3; fiberDetectedError = 3;
return; return;
} }
nano_fiber_sem_take_wait(&wakeFiber); /* Wait forever - let task run */ nano_fiber_sem_take_wait(&wakeFiber); /* Wait forever - let task run */
/* Fiber to wait on a timer that will be stopped by another fiber */ /* Fiber to wait on a timer that will be stopped by another fiber */
TC_PRINT("Fiber to stop a timer that has a waiting fiber\n"); TC_PRINT("Fiber to stop a timer that has a waiting fiber\n");
fiber_fiber_start(fiber2Stack, FIBER2_STACKSIZE, fiber2Entry, fiber_fiber_start(fiber2Stack, FIBER2_STACKSIZE, fiber2Entry,
0, 0, FIBER2_PRIORITY, 0); 0, 0, FIBER2_PRIORITY, 0);
nano_fiber_timer_start(&timer, TWO_SECONDS); /* Start timer */ nano_fiber_timer_start(&timer, TWO_SECONDS); /* Start timer */
result = nano_fiber_timer_wait(&timer); /* Wait on timer */ result = nano_fiber_timer_wait(&timer); /* Wait on timer */
/* Control switches to newly created fiber #2 before coming back. */ /* Control switches to newly created fiber #2 before coming back. */
if (result != NULL) { if (result != NULL) {
fiberDetectedError = 4; fiberDetectedError = 4;
nano_fiber_sem_give(&wakeTask); nano_fiber_sem_give(&wakeTask);
return; return;
} }
/* Fiber to wait on timer that will be stopped by the task */ /* Fiber to wait on timer that will be stopped by the task */
TC_PRINT("Task to stop a timer that has a waiting fiber\n"); TC_PRINT("Task to stop a timer that has a waiting fiber\n");
nano_fiber_sem_give(&wakeTask); nano_fiber_sem_give(&wakeTask);
nano_fiber_timer_start(&timer, TWO_SECONDS); nano_fiber_timer_start(&timer, TWO_SECONDS);
@ -430,7 +430,7 @@ static void fiberEntry(int arg1, int arg2)
if (result != NULL) { if (result != NULL) {
fiberDetectedError = 5; fiberDetectedError = 5;
return; return;
} }
nano_fiber_sem_give(&wakeTask); nano_fiber_sem_give(&wakeTask);
} }
@ -454,10 +454,10 @@ int nano_cycle_get_32Test(void)
timeStamp2 = nano_cycle_get_32(); timeStamp2 = nano_cycle_get_32();
if (timeStamp2 < timeStamp1) { if (timeStamp2 < timeStamp1) {
TC_ERROR("Timestamp value not increasing with successive calls\n"); TC_ERROR("Timestamp value not increasing with successive calls\n");
return TC_FAIL; return TC_FAIL;
}
} }
}
return TC_PASS; return TC_PASS;
} }
@ -481,37 +481,37 @@ void main(void)
TC_PRINT("Task testing basic timer functionality\n"); TC_PRINT("Task testing basic timer functionality\n");
rv = basicTimerWait(nano_task_timer_start, nano_task_timer_wait, rv = basicTimerWait(nano_task_timer_start, nano_task_timer_wait,
nano_task_timer_test, &timer, timerData, TWO_SECONDS); nano_task_timer_test, &timer, timerData, TWO_SECONDS);
if (rv != TC_PASS) { if (rv != TC_PASS) {
TC_ERROR("Task-level of waiting for timers failed\n"); TC_ERROR("Task-level of waiting for timers failed\n");
goto doneTests; goto doneTests;
} }
/* Check that timers expire in the correct order */ /* Check that timers expire in the correct order */
TC_PRINT("Task testing timers expire in the correct order\n"); TC_PRINT("Task testing timers expire in the correct order\n");
startTimers(nano_task_timer_start); startTimers(nano_task_timer_start);
rv = busyWaitTimers(nano_task_timer_test); rv = busyWaitTimers(nano_task_timer_test);
if (rv != TC_PASS) { if (rv != TC_PASS) {
TC_ERROR("Task-level timer expiration order failed\n"); TC_ERROR("Task-level timer expiration order failed\n");
goto doneTests; goto doneTests;
} }
/* Check that timers can be stopped */ /* Check that timers can be stopped */
TC_PRINT("Task testing the stopping of timers\n"); TC_PRINT("Task testing the stopping of timers\n");
startTimers(nano_task_timer_start); startTimers(nano_task_timer_start);
rv = stopTimers(nano_task_timer_stop, nano_task_timer_test); rv = stopTimers(nano_task_timer_stop, nano_task_timer_test);
if (rv != TC_PASS) { if (rv != TC_PASS) {
TC_ERROR("Task-level stopping of timers test failed\n"); TC_ERROR("Task-level stopping of timers test failed\n");
goto doneTests; goto doneTests;
} }
/* /*
* Start the fiber. The fiber will be given a higher priority than the * Start the fiber. The fiber will be given a higher priority than the
* main task. * main task.
*/ */
task_fiber_start(fiberStack, FIBER_STACKSIZE, fiberEntry, task_fiber_start(fiberStack, FIBER_STACKSIZE, fiberEntry,
0, 0, FIBER_PRIORITY, 0); 0, 0, FIBER_PRIORITY, 0);
nano_task_sem_take_wait(&wakeTask); nano_task_sem_take_wait(&wakeTask);
@ -519,7 +519,7 @@ void main(void)
TC_ERROR("Fiber-level of waiting for timers failed\n"); TC_ERROR("Fiber-level of waiting for timers failed\n");
rv = TC_FAIL; rv = TC_FAIL;
goto doneTests; goto doneTests;
} }
nano_task_sem_give(&wakeFiber); nano_task_sem_give(&wakeFiber);
nano_task_sem_take_wait(&wakeTask); nano_task_sem_take_wait(&wakeTask);
@ -528,7 +528,7 @@ void main(void)
TC_ERROR("Fiber-level timer expiration order failed\n"); TC_ERROR("Fiber-level timer expiration order failed\n");
rv = TC_FAIL; rv = TC_FAIL;
goto doneTests; goto doneTests;
} }
nano_task_sem_give(&wakeFiber); nano_task_sem_give(&wakeFiber);
nano_task_sem_take_wait(&wakeTask); nano_task_sem_take_wait(&wakeTask);
@ -537,7 +537,7 @@ void main(void)
TC_ERROR("Fiber-level stopping of timers test failed\n"); TC_ERROR("Fiber-level stopping of timers test failed\n");
rv = TC_FAIL; rv = TC_FAIL;
goto doneTests; goto doneTests;
} }
nano_task_sem_give(&wakeFiber); nano_task_sem_give(&wakeFiber);
nano_task_sem_take_wait(&wakeTask); nano_task_sem_take_wait(&wakeTask);
@ -545,27 +545,27 @@ void main(void)
TC_ERROR("Fiber stopping a timer waited upon by a fiber failed\n"); TC_ERROR("Fiber stopping a timer waited upon by a fiber failed\n");
rv = TC_FAIL; rv = TC_FAIL;
goto doneTests; goto doneTests;
} }
nano_task_timer_stop(&timer); nano_task_timer_stop(&timer);
if (fiberDetectedError == 5) { if (fiberDetectedError == 5) {
TC_ERROR("Task stopping a timer waited upon by a fiber failed\n"); TC_ERROR("Task stopping a timer waited upon by a fiber failed\n");
rv = TC_FAIL; rv = TC_FAIL;
goto doneTests; goto doneTests;
} }
nano_task_sem_take_wait(&wakeTask); nano_task_sem_take_wait(&wakeTask);
#if 0 #if 0
/* /*
* Due to recent changes in the i8253 file that correct an issue on real * Due to recent changes in the i8253 file that correct an issue on real
* hardware, this test will fail when run under QEMU. On QEMU, the i8253 * hardware, this test will fail when run under QEMU. On QEMU, the i8253
* timer can at appear to run backwards. This can generate a false * timer can at appear to run backwards. This can generate a false
* failure detection when this test is run under QEMU as part of the * failure detection when this test is run under QEMU as part of the
* standard sanity/regression checks. This suggests that the test is not * standard sanity/regression checks. This suggests that the test is not
* of high enough quality to be included during the standard sanity/ * of high enough quality to be included during the standard sanity/
* regression checks. * regression checks.
*/ */
TC_PRINT("Task testing of nano_cycle_get_32()\n"); TC_PRINT("Task testing of nano_cycle_get_32()\n");
rv = nano_cycle_get_32Test(); rv = nano_cycle_get_32Test();