Add control of sub-oplist when creating a new oplist of a container

Add test case of this new control
Fix some corner bugs in some containers evolving their own oplists.
This commit is contained in:
Patrick Pelissier committed 2020-05-15 21:19:39 +02:00
1 parent 0bedcba32b
commit 49a2e600c4
16 files changed
+388 -76

No files matched your search

+13 -6
View File
@@ -64,7 +64,8 @@ depend:
#####################################################################################################
check: depend
$(MAKE) `ls test-*.c|$(SED) 's/\.c/\.log/g'` checkfail
$(MAKE) `ls test-*.c|$(SED) 's/\.c/\.log/g'` `ls fail-*.c|$(SED) 's/\.c/\.log/g'`
@echo All tests passed
clean:
$(RM) *.exe *.s *~ *.o *.log a*.dat
@@ -74,19 +75,25 @@ clean:
distclean: clean
$(RM) *.depend depend
checkfail: fail-no-oplist
#####################################################################################################
# Proper failure generation (test if the code properly fails to compile)
#####################################################################################################
# TODO: should grep failure message?
fail-no-oplist:
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 ; do \
if $(CC) $(CFLAGS) $(CPPFLAGS) -g -c fail-no-oplist.c -o tmp.o -DTEST=$$i 2> fail-no-oplist-$$i.log ; then echo fail-no-oplist-$$i : ERROR; false; else echo fail-no-oplist-$$i : OK ; fi \
FAIL_BASE=
FAIL_SEQ=
fail-generic.log:
for i in `seq 1 $(FAIL_SEQ)` ; do \
if $(CC) $(CFLAGS) $(CPPFLAGS) -g -c $(FAIL_BASE).c -o tmp.o -DTEST=$$i 2> $(FAIL_BASE)-$$i.log ; then echo $(FAIL_BASE) -- TEST $$i : ERROR; false; else echo $(FAIL_BASE) -- TEST $$i : OK ; fi \
done
fail-no-oplist.log:
@$(MAKE) fail-generic.log FAIL_BASE=fail-no-oplist FAIL_SEQ=44
fail-chain-oplist.log:
@$(MAKE) fail-generic.log FAIL_BASE=fail-chain-oplist FAIL_SEQ=17
#####################################################################################################
# Code generation analysis
#####################################################################################################
+169
View File
@@ -0,0 +1,169 @@
/*
* Copyright (c) 2017-2020, Patrick Pelissier
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* + Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* + Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* The goal of this test file is to check that invalid constructs
are properly rejected, and that it generates a helpfull error
message in this case.
It tests invalid oplist in an _OPLIST constructor of a container.
*/
#include "m-core.h"
#if !defined(TEST)
# warning Please define TEST variable to select the test to run
#elif TEST == 1
#include "m-array.h"
ARRAY_DEF(array, int)
ARRAY_DEF(array2, array_t, ARRAY_OPLIST(array, DEFAULT_OPLIST))
#elif TEST == 2
#include "m-list.h"
LIST_DEF(list, int)
LIST_DEF(list2, list_t, LIST_OPLIST(list, DEFAULT_OPLIST))
#elif TEST == 3
#include "m-deque.h"
DEQUE_DEF(deque, int)
DEQUE_DEF(deque2, deque_t, DEQUE_OPLIST(deque, DEFAULT_OPLIST))
#elif TEST == 4
#include "m-bptree.h"
BPTREE_DEF(bptree, 4, int)
BPTREE_DEF(bptree2, 5, bptree_t, BPTREE_OPLIST(bptree, DEFAULT_OPLIST))
#elif TEST == 5
#include "m-bptree.h"
BPTREE_DEF2(bptree, 4, int, int)
BPTREE_DEF2(bptree2, 5, bptree_t, BPTREE_OPLIST2(bptree, DEFAULT_OPLIST, M_DEFAULT_OPLIST), int, M_DEFAULT_OPLIST)
#elif TEST == 6
#include "m-bptree.h"
BPTREE_DEF2(bptree, 4, int, int)
BPTREE_DEF2(bptree2, 5, bptree_t, BPTREE_OPLIST2(bptree, M_DEFAULT_OPLIST, DEFAULT_OPLIST), int, M_DEFAULT_OPLIST)
#elif TEST == 7
#include "m-buffer.h"
BUFFER_DEF(buffer, int, 4, BUFFER_THREAD_UNSAFE)
BUFFER_DEF(buffer2, buffer_t, 5, BUFFER_QUEUE, BUFFER_OPLIST(buffer, DEFAULT_OPLIST))
#elif TEST == 8
#include "m-array.h"
#include "m-concurrent.h"
ARRAY_DEF(array, int)
CONCURRENT_DEF(array2, array_t, ARRAY_OPLIST(array, M_DEFAULT_OPLIST))
ARRAY_DEF(array3, array2_t, CONCURRENT_OPLIST(array2, ARRAY_OPLIST(array, DEFAULT_OPLIST)))
#elif TEST == 9
#include "m-dict.h"
DICT_DEF2(dict, int, int)
DICT_DEF2(dict2, int, M_DEFAULT_OPLIST, dict_t, DICT_OPLIST(dict, DEFAULT_OPLIST, M_DEFAULT_OPLIST) )
#elif TEST == 10
#include "m-dict.h"
DICT_DEF2(dict, int, int)
DICT_DEF2(dict2, int, M_DEFAULT_OPLIST, dict_t, DICT_OPLIST(dict, M_DEFAULT_OPLIST, DEFAULT_OPLIST) )
#elif TEST == 11
#include "m-dict.h"
#include "m-array.h"
DICT_SET_DEF(dict, int)
ARRAY_DEF(array, dict_t, DICT_SET_OPLIST(dict, DEFAULT_OPLIST) )
#elif TEST == 12
#include "m-i-list.h"
#include "m-concurrent.h"
typedef struct tmp_str_s {
ILIST_INTERFACE(tmpstr, struct tmp_str_s);
int n;
} tmp_str_t;
ILIST_DEF(tmpstr, tmp_str_t, (CLEAR(M_NOTHING_DEFAULT)))
CONCURRENT_DEF(array, tmpstr_t, ILIST_OPLIST(tmpstr, X()))
#elif TEST == 13
#include "m-i-shared.h"
#include "m-concurrent.h"
typedef struct tmp_str_s {
ISHARED_PTR_INTERFACE(tmpstr, struct tmp_str_s);
int n;
} tmp_str_t;
ISHARED_PTR_DEF(tmpstr, tmp_str_t, (CLEAR(M_NOTHING_DEFAULT)))
CONCURRENT_DEF(array, tmpstr_t, ISHARED_PTR_OPLIST(tmpstr, X()))
#elif TEST == 14
#include "m-prioqueue.h"
PRIOQUEUE_DEF(prioqueue, int)
PRIOQUEUE_DEF(prioqueue2, prioqueue_t, PRIOQUEUE_OPLIST(prioqueue, M_DEFAULT_OPLIST()))
#elif TEST == 15
#include "m-rbtree.h"
RBTREE_DEF(rbtree, int)
RBTREE_DEF(rbtree2, rbtree_t, RBTREE_OPLIST(rbtree, M_DEFAULT_OPLIST2))
#elif TEST == 16
#include "m-shared.h"
SHARED_PTR_DEF(shared, int)
SHARED_PTR_DEF(shared2, shared_t, SHARED_PTR_OPLIST(shared, M_DEFAULT_OPLISTop))
#elif TEST == 17
#include "m-snapshot.h"
SNAPSHOT_SPSC_DEF(shared, int)
SNAPSHOT_SPSC_DEF(shared2, shared_t, SNAPSHOT_OPLIST(shared, M_DEFAULT_OPLIST x))
#else
# warning TEST variable is out of range.
#endif