Skip to content

Commit

Permalink
example code cleanup: cpplint whitespace adherence
Browse files Browse the repository at this point in the history
This PR is whitespace only in code, to adhere to the rules of cpplint,
plus a note in the CONTRIBUTING.md file to note that cpplint should be
used.
  • Loading branch information
beerriot committed Sep 10, 2018
1 parent d6101d6 commit e95fb1e
Show file tree
Hide file tree
Showing 4 changed files with 317 additions and 285 deletions.
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Expand Up @@ -70,6 +70,16 @@ Be sure to include any related GitHub issue references in the commit message. S
[GFM syntax](https://guides.github.com/features/mastering-markdown/#GitHub-flavored-markdown) for referencing issues
and commits.

### Formatting Code

We follow the guidelines outlined by the
[Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html).
If you use emacs, consider installing
[google-c-style.el](https://raw.githubusercontent.com/google/styleguide/gh-pages/google-c-style.el).
Please run
[cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint)
against your changes, to ensure adherence to the guidelines.

## Reporting Bugs and Creating Issues

When opening a new issue, try to roughly follow the commit message format conventions above.
176 changes: 86 additions & 90 deletions bftengine/tests/simpleTest/client.cpp
Expand Up @@ -4,7 +4,7 @@
#include <string>
#include <thread>

#include "CommFactory.hpp"
#include "CommFactory.hpp"

#include "commonDefs.h"
#include "SimpleClient.hpp"
Expand All @@ -14,92 +14,88 @@ using namespace bftEngine;

PlainUdpConfig getUDPConfig(uint16_t id);

int main(int argc, char **argv)
{
const int16_t id = 4;
const int numOfOperations = 2800;
const int readMod = 7;

SeqNumberGeneratorForClientRequests* pSeqGen = SeqNumberGeneratorForClientRequests::createSeqNumberGeneratorForClientRequests();

PlainUdpConfig udpConf = getUDPConfig(id);

ICommunication* comm = PlainUDPCommunication::create(udpConf);
SimpleClient* client = SimpleClient::createSimpleClient(comm, id, 1, 0);

comm->Start();

uint64_t expectedStateNum = 0;
bool hasExpectedStateNum = false;
uint64_t expectedLastValue = 0;
bool hasExpectedLastValue = false;

for (int i = 1; i <= numOfOperations; i++)
{
if (i % readMod == 0) // if read
{
char replyBuffer[sizeof(uint64_t)];

uint64_t reqId = READ_VAL_REQ;
uint32_t actualReplyLength = 0;
client->sendRequest(true, (char*)&reqId, sizeof(uint64_t),
pSeqGen->generateUniqueSequenceNumberForRequest(),
SimpleClient::INFINITE_TIMEOUT,
sizeof(uint64_t),
replyBuffer,
actualReplyLength);

assert(actualReplyLength == sizeof(uint64_t));

uint64_t retVal = *((uint64_t*)replyBuffer);

if (hasExpectedLastValue)
assert(retVal == expectedLastValue);
}
else // if write
{
char requestBuffer[sizeof(uint64_t) * 2];
char replyBuffer[sizeof(uint64_t)];

if(hasExpectedStateNum) expectedStateNum++;

if (!hasExpectedLastValue) hasExpectedLastValue = true;

expectedLastValue = (i + 1)*(i + 7)*(i + 18);

uint64_t* pReqId = (uint64_t*)requestBuffer;
uint64_t* pReqVal = (pReqId + 1);
*pReqId = SET_VAL_REQ;
*pReqVal = expectedLastValue;
uint32_t actualReplyLength = 0;
client->sendRequest(false, requestBuffer, sizeof(uint64_t)*2,
pSeqGen->generateUniqueSequenceNumberForRequest(),
SimpleClient::INFINITE_TIMEOUT,
sizeof(uint64_t),
replyBuffer,
actualReplyLength);

assert(actualReplyLength == sizeof(uint64_t));

uint64_t retVal = *((uint64_t*)replyBuffer);

if (hasExpectedStateNum)
{
assert(retVal == expectedStateNum);
}
else
{
hasExpectedStateNum = true;
expectedStateNum = retVal;
}
}
}

comm->Stop();

delete pSeqGen;
delete client;
delete comm;

return 0;
}
int main(int argc, char **argv) {
const int16_t id = 4;
const int numOfOperations = 2800;
const int readMod = 7;

SeqNumberGeneratorForClientRequests* pSeqGen =
SeqNumberGeneratorForClientRequests::
createSeqNumberGeneratorForClientRequests();

PlainUdpConfig udpConf = getUDPConfig(id);

ICommunication* comm = PlainUDPCommunication::create(udpConf);
SimpleClient* client = SimpleClient::createSimpleClient(comm, id, 1, 0);

comm->Start();

uint64_t expectedStateNum = 0;
bool hasExpectedStateNum = false;
uint64_t expectedLastValue = 0;
bool hasExpectedLastValue = false;

for (int i = 1; i <= numOfOperations; i++) {
if (i % readMod == 0) {
// if read
char replyBuffer[sizeof(uint64_t)];

uint64_t reqId = READ_VAL_REQ;
uint32_t actualReplyLength = 0;
client->sendRequest(true, (char*)&reqId, sizeof(uint64_t),
pSeqGen->generateUniqueSequenceNumberForRequest(),
SimpleClient::INFINITE_TIMEOUT,
sizeof(uint64_t),
replyBuffer,
actualReplyLength);

assert(actualReplyLength == sizeof(uint64_t));

uint64_t retVal = *((uint64_t*)replyBuffer);

if (hasExpectedLastValue)
assert(retVal == expectedLastValue);
} else {
// if write
char requestBuffer[sizeof(uint64_t) * 2];
char replyBuffer[sizeof(uint64_t)];

if (hasExpectedStateNum) expectedStateNum++;

if (!hasExpectedLastValue) hasExpectedLastValue = true;

expectedLastValue = (i + 1)*(i + 7)*(i + 18);

uint64_t* pReqId = (uint64_t*)requestBuffer;
uint64_t* pReqVal = (pReqId + 1);
*pReqId = SET_VAL_REQ;
*pReqVal = expectedLastValue;
uint32_t actualReplyLength = 0;
client->sendRequest(false, requestBuffer, sizeof(uint64_t)*2,
pSeqGen->generateUniqueSequenceNumberForRequest(),
SimpleClient::INFINITE_TIMEOUT,
sizeof(uint64_t),
replyBuffer,
actualReplyLength);

assert(actualReplyLength == sizeof(uint64_t));

uint64_t retVal = *((uint64_t*)replyBuffer);

if (hasExpectedStateNum) {
assert(retVal == expectedStateNum);
} else {
hasExpectedStateNum = true;
expectedStateNum = retVal;
}
}
}

comm->Stop();

delete pSeqGen;
delete client;
delete comm;

return 0;
}

0 comments on commit e95fb1e

Please sign in to comment.