1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-29 08:21:15 +03:00

Reformat all code to coding standard

This commit is contained in:
Andrew Hutchings
2017-10-26 17:18:17 +01:00
parent 4985f3456e
commit 01446d1e22
1296 changed files with 403852 additions and 353747 deletions

View File

@ -44,210 +44,242 @@ using namespace rwlock;
int threadStop;
static void *RWRunner(void *arg)
static void* RWRunner(void* arg)
{
struct timeval tv;
int op, op2, interval;
RWLock* rwlock;
gettimeofday(&tv, NULL);
rwlock = new RWLock(reinterpret_cast<int64_t>(arg));
while (!threadStop) {
op = rand_r(reinterpret_cast<uint32_t *>(&tv.tv_usec)) % 10;
if (op < 8) { // read
interval = rand_r(reinterpret_cast<uint32_t *>(&tv.tv_usec)) % 100000;
rwlock->read_lock();
rwlock->lock();
CPPUNIT_ASSERT(rwlock->getReading() > 0);
CPPUNIT_ASSERT(rwlock->getWriting() == 0);
rwlock->unlock();
usleep(interval);
struct timeval tv;
int op, op2, interval;
RWLock* rwlock;
op2 = rand_r(reinterpret_cast<uint32_t *>(&tv.tv_usec)) % 2;
if (op2) {
rwlock->upgrade_to_write();
rwlock->lock();
CPPUNIT_ASSERT(rwlock->getReading() == 0);
CPPUNIT_ASSERT(rwlock->getWriting() == 1);
rwlock->unlock();
usleep(interval);
rwlock->write_unlock();
}
else {
/* For testing the lock recovery code in the BRM workernodes */
/*
int crash = rand_r((uint32_t *) &tv.tv_usec) % 100;
if (crash > 0) // 1% chance of crashing
rwlock->read_unlock();
*/
}
}
else if (op < 9) { // write
interval = rand_r(reinterpret_cast<uint32_t *>(&tv.tv_usec)) % 100000;
rwlock->write_lock();
rwlock->lock();
CPPUNIT_ASSERT(rwlock->getReading() == 0);
CPPUNIT_ASSERT(rwlock->getWriting() == 1);
rwlock->unlock();
usleep(interval);
gettimeofday(&tv, NULL);
rwlock = new RWLock(reinterpret_cast<int64_t>(arg));
op2 = rand_r(reinterpret_cast<uint32_t *>(&tv.tv_usec)) % 2;
if (op2) {
rwlock->downgrade_to_read();
rwlock->lock();
CPPUNIT_ASSERT(rwlock->getReading() > 0);
CPPUNIT_ASSERT(rwlock->getWriting() == 0);
rwlock->unlock();
usleep(interval);
rwlock->read_unlock();
}
else
while (!threadStop)
{
op = rand_r(reinterpret_cast<uint32_t*>(&tv.tv_usec)) % 10;
rwlock->write_unlock();
}
else if (op == 9) { // delete
delete rwlock;
rwlock = new RWLock(reinterpret_cast<int64_t>(arg));
}
}
delete rwlock;
pthread_exit(0);
if (op < 8) // read
{
interval = rand_r(reinterpret_cast<uint32_t*>(&tv.tv_usec)) % 100000;
rwlock->read_lock();
rwlock->lock();
CPPUNIT_ASSERT(rwlock->getReading() > 0);
CPPUNIT_ASSERT(rwlock->getWriting() == 0);
rwlock->unlock();
usleep(interval);
op2 = rand_r(reinterpret_cast<uint32_t*>(&tv.tv_usec)) % 2;
if (op2)
{
rwlock->upgrade_to_write();
rwlock->lock();
CPPUNIT_ASSERT(rwlock->getReading() == 0);
CPPUNIT_ASSERT(rwlock->getWriting() == 1);
rwlock->unlock();
usleep(interval);
rwlock->write_unlock();
}
else
{
/* For testing the lock recovery code in the BRM workernodes */
/*
int crash = rand_r((uint32_t *) &tv.tv_usec) % 100;
if (crash > 0) // 1% chance of crashing
rwlock->read_unlock();
*/
}
}
else if (op < 9) // write
{
interval = rand_r(reinterpret_cast<uint32_t*>(&tv.tv_usec)) % 100000;
rwlock->write_lock();
rwlock->lock();
CPPUNIT_ASSERT(rwlock->getReading() == 0);
CPPUNIT_ASSERT(rwlock->getWriting() == 1);
rwlock->unlock();
usleep(interval);
op2 = rand_r(reinterpret_cast<uint32_t*>(&tv.tv_usec)) % 2;
if (op2)
{
rwlock->downgrade_to_read();
rwlock->lock();
CPPUNIT_ASSERT(rwlock->getReading() > 0);
CPPUNIT_ASSERT(rwlock->getWriting() == 0);
rwlock->unlock();
usleep(interval);
rwlock->read_unlock();
}
else
rwlock->write_unlock();
}
else if (op == 9) // delete
{
delete rwlock;
rwlock = new RWLock(reinterpret_cast<int64_t>(arg));
}
}
delete rwlock;
pthread_exit(0);
}
static void *RWRunner_local(void *arg)
static void* RWRunner_local(void* arg)
{
struct timeval tv;
int op, op2, interval;
RWLock_local* rwlock = reinterpret_cast<RWLock_local *>(arg);
gettimeofday(&tv, NULL);
while (!threadStop) {
op = rand_r(reinterpret_cast<uint32_t *>(&tv.tv_usec)) % 10;
struct timeval tv;
int op, op2, interval;
RWLock_local* rwlock = reinterpret_cast<RWLock_local*>(arg);
gettimeofday(&tv, NULL);
while (!threadStop)
{
op = rand_r(reinterpret_cast<uint32_t*>(&tv.tv_usec)) % 10;
// cout << "doing op " << op << endl;
switch(op) {
case 0: //read
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
{
interval = rand_r(reinterpret_cast<uint32_t *>(&tv.tv_usec)) % 100000;
rwlock->read_lock();
rwlock->lock();
CPPUNIT_ASSERT(rwlock->getReading() > 0);
CPPUNIT_ASSERT(rwlock->getWriting() == 0);
rwlock->unlock();
usleep(interval);
op2 = rand_r(reinterpret_cast<uint32_t *>(&tv.tv_usec)) % 2;
if (op2) {
rwlock->upgrade_to_write();
switch (op)
{
case 0: //read
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
{
interval = rand_r(reinterpret_cast<uint32_t*>(&tv.tv_usec)) % 100000;
rwlock->read_lock();
rwlock->lock();
CPPUNIT_ASSERT(rwlock->getReading() > 0);
CPPUNIT_ASSERT(rwlock->getWriting() == 0);
rwlock->unlock();
usleep(interval);
op2 = rand_r(reinterpret_cast<uint32_t*>(&tv.tv_usec)) % 2;
if (op2)
{
rwlock->upgrade_to_write();
// rwlock->lock();
CPPUNIT_ASSERT(rwlock->getReading() == 0);
CPPUNIT_ASSERT(rwlock->getWriting() == 1);
CPPUNIT_ASSERT(rwlock->getReading() == 0);
CPPUNIT_ASSERT(rwlock->getWriting() == 1);
// rwlock->unlock();
usleep(interval);
rwlock->write_unlock();
}
break;
}
case 9: //write
{
interval = rand_r(reinterpret_cast<uint32_t *>(&tv.tv_usec)) % 100000;
rwlock->write_lock();
usleep(interval);
rwlock->write_unlock();
}
break;
}
case 9: //write
{
interval = rand_r(reinterpret_cast<uint32_t*>(&tv.tv_usec)) % 100000;
rwlock->write_lock();
// rwlock->lock();
CPPUNIT_ASSERT(rwlock->getReading() == 0);
CPPUNIT_ASSERT(rwlock->getWriting() == 1);
CPPUNIT_ASSERT(rwlock->getReading() == 0);
CPPUNIT_ASSERT(rwlock->getWriting() == 1);
// rwlock->unlock();
usleep(interval);
op2 = rand_r(reinterpret_cast<uint32_t *>(&tv.tv_usec)) % 2;
if (op2) {
rwlock->downgrade_to_read();
rwlock->lock();
CPPUNIT_ASSERT(rwlock->getReading() > 0);
CPPUNIT_ASSERT(rwlock->getWriting() == 0);
rwlock->unlock();
usleep(interval);
rwlock->read_unlock();
}
else
rwlock->write_unlock();
break;
}
default:
break;
}
}
pthread_exit(0);
usleep(interval);
op2 = rand_r(reinterpret_cast<uint32_t*>(&tv.tv_usec)) % 2;
if (op2)
{
rwlock->downgrade_to_read();
rwlock->lock();
CPPUNIT_ASSERT(rwlock->getReading() > 0);
CPPUNIT_ASSERT(rwlock->getWriting() == 0);
rwlock->unlock();
usleep(interval);
rwlock->read_unlock();
}
else
rwlock->write_unlock();
break;
}
default:
break;
}
}
pthread_exit(0);
}
class RWLockTest : public CppUnit::TestFixture {
class RWLockTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(RWLockTest);
CPPUNIT_TEST_SUITE(RWLockTest);
CPPUNIT_TEST(LongRWTest_1);
CPPUNIT_TEST(LongRWTest_1);
//CPPUNIT_TEST(LongRWLocalTest_1);
CPPUNIT_TEST_SUITE_END();
CPPUNIT_TEST_SUITE_END();
private:
public:
void LongRWTest_1() {
int key = 0x20000; // the extentmap key
const int threadCount = 30;
int i;
pthread_t threads[threadCount];
cerr << endl << "Multithreaded RWLock test. "
"This runs for 60 minutes." << endl;
threadStop = 0;
for (i = 0; i < threadCount; i++) {
if (pthread_create(&threads[i], NULL, RWRunner,
reinterpret_cast<void *>(key)) < 0)
throw logic_error("Error creating threads for the ipc test");
}
sleep(3600);
threadStop = 1;
for (i = 0; i < threadCount; i++) {
cerr << "Waiting for thread #" << i << endl;
pthread_join(threads[i], NULL);
}
}
void LongRWTest_1()
{
int key = 0x20000; // the extentmap key
void LongRWLocalTest_1() {
const int threadCount = 40;
int i;
pthread_t threads[threadCount];
RWLock_local rwlock;
cerr << endl << "Multithreaded RWLock_local test. "
"This runs for 30-60 seconds." << endl;
threadStop = 0;
for (i = 0; i < threadCount; i++) {
if (pthread_create(&threads[i], NULL, RWRunner_local,
reinterpret_cast<void *>(&rwlock)) < 0)
throw logic_error("Error creating threads for the local test");
}
sleep(30);
threadStop = 1;
for (i = 0; i < threadCount; i++) {
cerr << "Waiting for thread #" << i << endl;
pthread_join(threads[i], NULL);
}
}
const int threadCount = 30;
int i;
pthread_t threads[threadCount];
cerr << endl << "Multithreaded RWLock test. "
"This runs for 60 minutes." << endl;
threadStop = 0;
for (i = 0; i < threadCount; i++)
{
if (pthread_create(&threads[i], NULL, RWRunner,
reinterpret_cast<void*>(key)) < 0)
throw logic_error("Error creating threads for the ipc test");
}
sleep(3600);
threadStop = 1;
for (i = 0; i < threadCount; i++)
{
cerr << "Waiting for thread #" << i << endl;
pthread_join(threads[i], NULL);
}
}
void LongRWLocalTest_1()
{
const int threadCount = 40;
int i;
pthread_t threads[threadCount];
RWLock_local rwlock;
cerr << endl << "Multithreaded RWLock_local test. "
"This runs for 30-60 seconds." << endl;
threadStop = 0;
for (i = 0; i < threadCount; i++)
{
if (pthread_create(&threads[i], NULL, RWRunner_local,
reinterpret_cast<void*>(&rwlock)) < 0)
throw logic_error("Error creating threads for the local test");
}
sleep(30);
threadStop = 1;
for (i = 0; i < threadCount; i++)
{
cerr << "Waiting for thread #" << i << endl;
pthread_join(threads[i], NULL);
}
}
};
@ -256,13 +288,13 @@ CPPUNIT_TEST_SUITE_REGISTRATION( RWLockTest );
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
int main( int argc, char **argv)
int main( int argc, char** argv)
{
CppUnit::TextUi::TestRunner runner;
CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest( registry.makeTest() );
bool wasSuccessful = runner.run( "", false );
return (wasSuccessful ? 0 : 1);
CppUnit::TextUi::TestRunner runner;
CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest( registry.makeTest() );
bool wasSuccessful = runner.run( "", false );
return (wasSuccessful ? 0 : 1);
}