Author: bart
Date: Wed Oct 23 12:37:44 2013
New Revision: 13680
Log:
drd/tests: Add std_list and std_string test programs
Added:
trunk/drd/tests/std_list.cpp
trunk/drd/tests/std_list.stderr.exp
trunk/drd/tests/std_list.vgtest
trunk/drd/tests/std_string.cpp
trunk/drd/tests/std_string.stderr.exp
trunk/drd/tests/std_string.vgtest
Modified:
trunk/drd/tests/Makefile.am
Modified: trunk/drd/tests/Makefile.am
==============================================================================
--- trunk/drd/tests/Makefile.am (original)
+++ trunk/drd/tests/Makefile.am Wed Oct 23 12:37:44 2013
@@ -230,6 +230,10 @@
sigalrm.vgtest \
sigaltstack.stderr.exp \
sigaltstack.vgtest \
+ std_list.stderr.exp \
+ std_list.vgtest \
+ std_string.stderr.exp \
+ std_string.vgtest \
std_thread.stderr.exp \
std_thread.vgtest \
tc01_simple_race.stderr.exp \
@@ -370,6 +374,8 @@
if CXX_CAN_INCLUDE_THREAD_HEADER
if HAVE_SHARED_POINTER_ANNOTATION
check_PROGRAMS += \
+ std_list \
+ std_string \
std_thread
endif
endif
@@ -450,6 +456,12 @@
matinv_LDADD = $(LDADD) -lm
endif
+std_list_SOURCES = std_list.cpp
+std_list_CXXFLAGS = $(AM_CXXFLAGS) -std=c++0x -Wno-sign-compare
+
+std_string_SOURCES = std_string.cpp
+std_string_CXXFLAGS = $(AM_CXXFLAGS) -std=c++0x -Wno-sign-compare
+
std_thread_SOURCES = std_thread.cpp
std_thread_CXXFLAGS = $(AM_CXXFLAGS) -std=c++0x
Added: trunk/drd/tests/std_list.cpp
==============================================================================
--- trunk/drd/tests/std_list.cpp (added)
+++ trunk/drd/tests/std_list.cpp Wed Oct 23 12:37:44 2013
@@ -0,0 +1,99 @@
+/*
+ * Test program that triggers strcpy() from one thread and a memory allocation
+ * immediately after the region read by strcpy() from another thread. Without
+ * strcpy() intercept there is about 50% chance that this test program triggers
+ * a false positive race report on Ubuntu 12.10 amd64.
+ *
+ * See also https://bugs.kde.org/show_bug.cgi?id=326436.
+ */
+
+#include <locale.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <pthread.h>
+#include <string.h>
+#include <string>
+#include <sstream>
+#include <list>
+
+using namespace std;
+
+class SubTest {
+public:
+ SubTest() {
+ list<int *> ffList;
+ ffList.push_back((int *) NULL);
+ for (list<int*>::iterator ff = ffList.begin(); ff != ffList.end(); ff++) {
+ usleep(1000);
+ }
+ }
+ void subTest() {
+ list<int *> ffList;
+ ffList.push_back((int *) NULL);
+ for (list<int*>::const_iterator ff = ffList.begin(); ff != ffList.end(); ff++) {
+ usleep(1000);
+ }
+ }
+};
+
+class Test {
+ SubTest *subTest;
+public:
+ void setUp() {
+ subTest = new SubTest();
+ setlocale(LC_ALL, "English");
+ }
+ void tearDown() {
+ delete subTest; }
+ void func1() {
+ for (size_t i = 0; i < 10000; i++) {
+ subTest->subTest();
+ usleep(1000);
+ }
+ }
+ void func2() {
+ usleep(1000);
+ }
+};
+
+void *func1(void *instance)
+{
+ Test *casted = reinterpret_cast<Test*>(instance);
+ casted->setUp();
+ casted->func1();
+ casted->tearDown();
+ return NULL;
+}
+
+void *func2(void *instance)
+{
+ Test *casted = reinterpret_cast<Test*>(instance);
+ casted->setUp();
+ casted->func2();
+ casted->tearDown();
+ return NULL;
+}
+
+int main(int argc, char* argv[])
+{
+ int err;
+ pthread_t thread1;
+ pthread_t thread2;
+ Test instance1;
+ Test instance2;
+
+ // create
+ err = pthread_create(&thread1, NULL, &func1, &instance1);
+ if (err != 0)
+ throw string("failed to create a thread.");
+ err = pthread_create(&thread2, NULL, &func2, &instance2);
+ if (err != 0)
+ throw string("failed to create a thread.");
+ // join
+ err = pthread_join(thread1, NULL);
+ if (err != 0)
+ throw string("Thread::join(): failed to join.");
+ err = pthread_join(thread2, NULL);
+ if (err != 0)
+ throw string("Thread::join(): failed to join.");
+}
Added: trunk/drd/tests/std_list.stderr.exp
==============================================================================
--- trunk/drd/tests/std_list.stderr.exp (added)
+++ trunk/drd/tests/std_list.stderr.exp Wed Oct 23 12:37:44 2013
@@ -0,0 +1,3 @@
+
+
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Added: trunk/drd/tests/std_list.vgtest
==============================================================================
--- trunk/drd/tests/std_list.vgtest (added)
+++ trunk/drd/tests/std_list.vgtest Wed Oct 23 12:37:44 2013
@@ -0,0 +1,4 @@
+prereq: test -e std_list && ./supported_libpthread
+vgopts: --check-stack-var=yes --show-confl-seg=no
+prog: std_list
+stderr_filter: filter_stderr
Added: trunk/drd/tests/std_string.cpp
==============================================================================
--- trunk/drd/tests/std_string.cpp (added)
+++ trunk/drd/tests/std_string.cpp Wed Oct 23 12:37:44 2013
@@ -0,0 +1,67 @@
+/*
+ * Test program that uses std::string object from more than one thread and
+ * that also triggers a call to __GI_strlen() (from inside strdup()). See also
+ * https://bugs.kde.org/show_bug.cgi?id=326091.
+ */
+
+#include <list>
+#include <string>
+#include <cstring>
+#include <pthread.h>
+#include <unistd.h>
+
+char* list2byteArray()
+{
+ size_t data_size = 24;
+ char *data = new char[data_size];
+ for (size_t i = 0; i < data_size; i++)
+ data[i] = 'a';
+ data[data_size - 1] = 0;
+ char *ret = strdup(data);
+ delete[] data;
+ return ret;
+}
+
+int addRecord()
+{
+ char *data = list2byteArray();
+ usleep(100);
+ free(data);
+ return 0;
+}
+
+void *fillTable(void *ptr)
+{
+ for (int i = 0; i < 100; i++) {
+ std::string id("000");
+ id.append(1, 'a' + i);
+ std::list<std::string> record;
+ record.push_back("some data");
+ addRecord();
+ }
+ usleep(1000 * 1000);
+ return NULL;
+}
+
+int main(int argc, char* argv[])
+{
+ pthread_t thread[2];
+
+ for (int i = 0; i < sizeof(thread)/sizeof(thread[0]); i++) {
+ int ret = pthread_create(&thread[i], NULL, &fillTable, NULL);
+ if (ret) {
+ fprintf(stderr, "Failed to create thread %d: %d\n", i, ret);
+ return 1;
+ }
+ }
+
+ for (int i = 0; i < sizeof(thread)/sizeof(thread[0]); i++) {
+ int ret = pthread_join(thread[i], NULL);
+ if (ret != 0) {
+ fprintf(stderr, "Failed to join thread %d: %d\n", i, ret);
+ return 1;
+ }
+ }
+
+ return 0;
+}
Added: trunk/drd/tests/std_string.stderr.exp
==============================================================================
--- trunk/drd/tests/std_string.stderr.exp (added)
+++ trunk/drd/tests/std_string.stderr.exp Wed Oct 23 12:37:44 2013
@@ -0,0 +1,3 @@
+
+
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Added: trunk/drd/tests/std_string.vgtest
==============================================================================
--- trunk/drd/tests/std_string.vgtest (added)
+++ trunk/drd/tests/std_string.vgtest Wed Oct 23 12:37:44 2013
@@ -0,0 +1,4 @@
+prereq: test -e std_string && ./supported_libpthread
+vgopts: --check-stack-var=yes --show-confl-seg=no
+prog: std_string
+stderr_filter: filter_stderr
|