From f3e6b18a4aa799d778ded7c952baeac6ae26ade0 Mon Sep 17 00:00:00 2001 From: Jennifer Averett Date: Wed, 26 Feb 2014 09:41:04 -0600 Subject: smptests: Add smppsxaffinity01. This test exercises the ability to obtain and modify the affinity field of the POSIX thread attributes. --- testsuites/smptests/smppsxaffinity01/init.c | 174 ++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 testsuites/smptests/smppsxaffinity01/init.c (limited to 'testsuites/smptests/smppsxaffinity01/init.c') diff --git a/testsuites/smptests/smppsxaffinity01/init.c b/testsuites/smptests/smppsxaffinity01/init.c new file mode 100644 index 0000000000..525b5f7d3c --- /dev/null +++ b/testsuites/smptests/smppsxaffinity01/init.c @@ -0,0 +1,174 @@ +/* + * COPYRIGHT (c) 1989-2014. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#define _GNU_SOURCE + +#include +#include +#include +#include + +#if HAVE_DECL_PTHREAD_GETAFFINITY_NP + +#define CPU_COUNT 4 + +pthread_t Init_id; + +/* forward declarations to avoid warnings */ +void *POSIX_Init(void *argument); +void Validate_attrgetaffinity_errors(void); +void Validate_attrsetaffinity_errors(void); +void Validate_attr(void); + +void Validate_attrgetaffinity_errors(void) +{ + int sc; + cpu_set_t cpuset; + pthread_attr_t attr; + + /* Verify pthread_attr_getaffinity_np validates attr */ + puts( "Init - pthread_attr_getaffinity_np - Invalid attr - EFAULT" ); + sc = pthread_attr_getaffinity_np( NULL, sizeof(cpu_set_t), &cpuset ); + rtems_test_assert( sc == EFAULT ); + + /* Verify pthread_attr_getaffinity_np validates cpuset */ + puts( "Init - pthread_attr_getaffinity_np - Invalid attr - EFAULT" ); + sc = pthread_attr_getaffinity_np( &attr, sizeof(cpu_set_t), NULL ); + rtems_test_assert( sc == EFAULT ); + + /* Verify pthread_attr_getaffinity_np validates cpusetsize */ + puts( "Init - pthread_attr_getaffinity_np - Invalid cpusetsize - EINVAL" ); + sc = pthread_attr_getaffinity_np( &attr, sizeof(cpu_set_t) * 2 , &cpuset ); + rtems_test_assert( sc == EINVAL ); + +} + +void Validate_attrsetaffinity_errors(void) +{ + int sc; + cpu_set_t cpuset; + pthread_attr_t attr; + + /* Verify pthread_attr_setaffinity_np validates attr. */ + puts( "Init - pthread_attr_setaffinity_np - Invalid attr - EFAULT" ); + sc = pthread_attr_setaffinity_np( NULL, sizeof(cpu_set_t), &cpuset ); + rtems_test_assert( sc == EFAULT ); + + /* Verify pthread_attr_setaffinity_np validates cpuset */ + puts( "Init - pthread_attr_setaffinity_np - Invalid attr - EFAULT" ); + sc = pthread_attr_setaffinity_np( &attr, sizeof(cpu_set_t), NULL ); + rtems_test_assert( sc == EFAULT ); + + /* Verify pthread_attr_setaffinity_np validates cpusetsize */ + puts( "Init - pthread_attr_setaffinity_np - Invalid cpusetsize - EINVAL" ); + sc = pthread_attr_setaffinity_np( &attr, sizeof(cpu_set_t) * 2 , &cpuset ); + rtems_test_assert( sc == EINVAL ); + + /* Verify pthread_attr_setaffinity_np validates cpuset greater than 0 */ + CPU_ZERO(&cpuset); + puts( "Init - pthread_attr_setaffinity_np - No cpus in cpuset - EINVAL" ); + sc = pthread_attr_setaffinity_np( &attr, sizeof(cpu_set_t) , &cpuset ); + rtems_test_assert( sc == EINVAL ); + + /* Verify pthread_attr_setaffinity_np validates invalid cpu in cpuset */ + CPU_FILL(&cpuset); + puts( "Init - pthread_attr_setaffinity_np - Too many cpus in cpuset - EINVAL" ); + sc = pthread_attr_setaffinity_np( &attr, sizeof(cpu_set_t) , &cpuset ); + rtems_test_assert( sc == EINVAL ); +} + +void Validate_attr(void ) +{ + int sc; + pthread_attr_t attr; + uint32_t cpus; + cpu_set_t cpuset1; + cpu_set_t cpuset2; + int i; + int priority; + + sc = pthread_getattr_np( Init_id, &attr ); + rtems_test_assert( sc == 0 ); + + priority = sched_get_priority_min( SCHED_FIFO ); + rtems_test_assert( priority != -1 ); + + + cpus = rtems_smp_get_processor_count(); + puts( + "Init - Validate pthread_attr_setaffinity_np and " + "pthread_attr_getaffinity_np" + ); + + /* Set each cpu seperately in the affinity set */ + for ( i=0; i + +/* global variables */ -- cgit v1.2.3