Skip to content

Commit

Permalink
chore: add clang-format check
Browse files Browse the repository at this point in the history
Signed-off-by: Jian Zhang <[email protected]>
  • Loading branch information
zz-jason committed Aug 11, 2024
1 parent d95bbbf commit 770fa8f
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 41 deletions.
29 changes: 17 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@ jobs:
sudo apt install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu;
sudo apt install -y curl zip unzip tar pkg-config;
sudo apt install -y autoconf libtool;
sudo ln -sf /usr/bin/cpp-13 /usr/bin/cpp;
sudo ln -sf /usr/bin/g++-13 /usr/bin/g++;
sudo ln -sf /usr/bin/gcc-13 /usr/bin/gcc;
sudo ln -sf /usr/bin/gcc-ar-13 /usr/bin/gcc-ar;
sudo ln -sf /usr/bin/gcc-nm-13 /usr/bin/gcc-nm;
sudo ln -sf /usr/bin/gcc-ranlib-13 /usr/bin/gcc-ranlib;
sudo ln -sf /usr/bin/gcov-13 /usr/bin/gcov;
sudo ln -sf /usr/bin/gcov-dump-13 /usr/bin/gcov-dump;
sudo ln -sf /usr/bin/gcov-tool-13 /usr/bin/gcov-tool;
sudo ln -sf /usr/bin/lto-dump-13 /usr/bin/lto-dump;
sudo ln -sf /usr/bin/g++-13 /usr/bin/c++;
sudo ln -sf /usr/bin/gcc-13 /usr/bin/cc;
sudo apt install -y clang-format-18;
sudo ln -sf /usr/bin/cpp-13 /usr/bin/cpp;
sudo ln -sf /usr/bin/g++-13 /usr/bin/g++;
sudo ln -sf /usr/bin/gcc-13 /usr/bin/gcc;
sudo ln -sf /usr/bin/gcc-ar-13 /usr/bin/gcc-ar;
sudo ln -sf /usr/bin/gcc-nm-13 /usr/bin/gcc-nm;
sudo ln -sf /usr/bin/gcc-ranlib-13 /usr/bin/gcc-ranlib;
sudo ln -sf /usr/bin/gcov-13 /usr/bin/gcov;
sudo ln -sf /usr/bin/gcov-dump-13 /usr/bin/gcov-dump;
sudo ln -sf /usr/bin/gcov-tool-13 /usr/bin/gcov-tool;
sudo ln -sf /usr/bin/lto-dump-13 /usr/bin/lto-dump;
sudo ln -sf /usr/bin/g++-13 /usr/bin/c++;
sudo ln -sf /usr/bin/gcc-13 /usr/bin/cc;
sudo ln -sf /usr/bin/clang-format-18 /usr/bin/clang-format;
pip3 install gcovr==6.0 --break-system-packages;
sudo git clone https://github.com/Microsoft/vcpkg.git /opt/vcpkg;
echo 'export VCPKG_ROOT=/opt/vcpkg' >> ~/.bashrc;
Expand All @@ -54,6 +56,9 @@ jobs:
- name: Cppcheck
run: cppcheck --project=build/debug_tsan/compile_commands.json -i tests --error-exitcode=1

- name: Check clang-format
run: cmake --build build/debug_tsan --target=check-format || echo "please fix code format via 'cmake --build build/debug_tsan --target=format'"

- name: Build project
run: cmake --build build/debug_tsan -j `nproc`

Expand Down
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ To run unittests in the debug mode:
ctest --test-dir build/debug
```

To check and fix code formatting wich `clang-format-18`:

```sh
# check format
cmake --build build/debug --target=check-format

# fix format
cmake --build build/debug --target=format
```

To run simple ycsb benchmarks:

```sh
Expand Down
3 changes: 1 addition & 2 deletions benchmarks/ycsb/YcsbRocksDb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ class YcsbRocksDb : public YcsbExecutor {
SCOPED_DEFER({
auto end = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
std::cout << "Done inserting"
<< ", time elapsed: " << duration / 1000000.0 << " seconds"
std::cout << "Done inserting" << ", time elapsed: " << duration / 1000000.0 << " seconds"
<< ", throughput: " << CalculateTps(start, end, FLAGS_ycsb_record_count) << " tps"
<< std::endl;
});
Expand Down
9 changes: 3 additions & 6 deletions include/leanstore/PerfEvent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,9 @@ struct PerfEvent {
}

// derived metrics
headerOut << ","
<< "IPC";
headerOut << ","
<< "CPU";
headerOut << ","
<< "GHz";
headerOut << "," << "IPC";
headerOut << "," << "CPU";
headerOut << "," << "GHz";
}
// -------------------------------------------------------------------------------------
void printCSVData(std::ostream& dataOut, uint64_t normalizationConstant) {
Expand Down
15 changes: 10 additions & 5 deletions include/leanstore/btree/core/WALMacros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,16 @@
entrySize1(Type, A1) + entrySize1(Type, A2) + entrySize1(Type, A3) + entrySize1(Type, A4)

#define WALUpdate1(Type, A1) \
{beforeWrapper1(Type, A1), afterWrapper1(Type, A1), entrySize1(Type, A1)}
{ beforeWrapper1(Type, A1), afterWrapper1(Type, A1), entrySize1(Type, A1) }
#define WALUpdate2(Type, A1, A2) \
{beforeWrapper2(Type, A1, A2), afterWrapper2(Type, A1, A2), entrySize2(Type, A1, A2)}
{ beforeWrapper2(Type, A1, A2), afterWrapper2(Type, A1, A2), entrySize2(Type, A1, A2) }
#define WALUpdate3(Type, A1, A2, A3) \
{beforeWrapper3(Type, A1, A2, A3), afterWrapper3(Type, A1, A2, A3), entrySize3(Type, A1, A2, A3)}
{ \
beforeWrapper3(Type, A1, A2, A3), afterWrapper3(Type, A1, A2, A3), \
entrySize3(Type, A1, A2, A3) \
}
#define WALUpdate4(Type, A1, A2, A3, A4) \
{beforeWrapper4(Type, A1, A2, A3, A4), afterWrapper4(Type, A1, A2, A3, A4), \
entrySize4(Type, A1, A2, A3, A4)}
{ \
beforeWrapper4(Type, A1, A2, A3, A4), afterWrapper4(Type, A1, A2, A3, A4), \
entrySize4(Type, A1, A2, A3, A4) \
}
2 changes: 1 addition & 1 deletion include/leanstore/buffer-manager/Swip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Swip {
};

//! Create an empty swip.
Swip() : mPageId(0) {};
Swip() : mPageId(0){};

//! Create an swip pointing to the buffer frame.
Swip(BufferFrame* bf) : mBf(bf) {
Expand Down
2 changes: 1 addition & 1 deletion src/concurrency/CRManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ CRManager::CRManager(leanstore::LeanStore* store) : mStore(store), mGroupCommitt
// create history storage for each worker
// History tree should be created after worker thread and group committer are
// started.
if(storeOption.mWorkerThreads > 0){
if (storeOption.mWorkerThreads > 0) {
mWorkerThreads[0]->SetJob([&]() { setupHistoryStorage4EachWorker(); });
mWorkerThreads[0]->Wait();
}
Expand Down
15 changes: 9 additions & 6 deletions tests/buffer-manager/AsyncWriteBufferTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <cstring>
#include <format>
#include <vector>

#include <fcntl.h>

namespace leanstore::storage::test {
Expand Down Expand Up @@ -106,12 +107,14 @@ TEST_F(AsyncWriteBufferTest, Basic) {
EXPECT_EQ(doneRequests, testMaxBatchSize);
EXPECT_EQ(testWriteBuffer.GetPendingRequests(), 0);

// check the flushed content
testWriteBuffer.IterateFlushedBfs([](BufferFrame& flushedBf, uint64_t flushedGsn){
EXPECT_FALSE(flushedBf.IsDirty());
EXPECT_FALSE(flushedBf.IsFree());
EXPECT_EQ(flushedGsn, 0);
}, testMaxBatchSize);
// check the flushed content
testWriteBuffer.IterateFlushedBfs(
[](BufferFrame& flushedBf, uint64_t flushedGsn) {
EXPECT_FALSE(flushedBf.IsDirty());
EXPECT_FALSE(flushedBf.IsFree());
EXPECT_EQ(flushedGsn, 0);
},
testMaxBatchSize);

// read the file content
for (int i = 0; i < testMaxBatchSize; i++) {
Expand Down
17 changes: 9 additions & 8 deletions tests/buffer-manager/PageEvictorTest.cpp
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
#include "leanstore/buffer-manager/AsyncWriteBuffer.hpp"
#include "leanstore/buffer-manager/PageEvictor.hpp"

#include "leanstore/buffer-manager/AsyncWriteBuffer.hpp"
#include "leanstore/buffer-manager/BufferFrame.hpp"
#include "leanstore/buffer-manager/BufferManager.hpp"
#include "leanstore/buffer-manager/Swip.hpp"
#include "leanstore/utils/Defer.hpp"
#include "leanstore/utils/Log.hpp"
#include "leanstore/utils/Misc.hpp"
#include "leanstore/utils/RandomGenerator.hpp"
#include "leanstore/buffer-manager/PageEvictor.hpp"
#include "leanstore/buffer-manager/BufferManager.hpp"
#include <iostream>

#include <gtest/gtest.h>

#include <cstddef>
#include <cstdint>
#include <cstring>
#include <format>
#include <iostream>

#include <fcntl.h>

namespace leanstore::storage::test {
class PageEvictorTest : public ::testing::Test {
protected:
protected:
std::unique_ptr<LeanStore> mStore;

PageEvictorTest() = default;

~PageEvictorTest() = default;
void SetUp() override {

void SetUp() override {
auto* curTest = ::testing::UnitTest::GetInstance()->current_test_info();
auto curTestName = std::string(curTest->test_case_name()) + "_" + std::string(curTest->name());
const int pageSize = 4096;
Expand All @@ -41,11 +43,10 @@ class PageEvictorTest : public ::testing::Test {
.mFreePct = 20,
.mEnableBulkInsert = false,
.mEnableEagerGc = false,

});
ASSERT_TRUE(res);
mStore = std::move(res.value());

}
};

Expand Down

0 comments on commit 770fa8f

Please sign in to comment.