Skip to content

Commit

Permalink
Merge branch 'master' into ktf-patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
ktf authored Nov 26, 2024
2 parents 4413baa + 57cd35b commit c1192b7
Show file tree
Hide file tree
Showing 24 changed files with 64 additions and 43 deletions.
18 changes: 10 additions & 8 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@ name: Clang format
on: [pull_request]

jobs:
clang-format-8:
runs-on: ubuntu-latest
clang-format:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Run clang-foramt on changed files
- name: Run clang-format on changed files
run: |
set -x
sudo apt install clang-format
git config --global --add safe.directory '*'
git fetch origin ${{ github.event.pull_request.base.ref }}
git fetch origin pull/${{ github.event.pull_request.number }}/head:${{ github.event.pull_request.head.ref }}
BASE_COMMIT=$(git rev-parse ${{ github.event.pull_request.base.sha }})
COMMIT_FILES=$(git diff --name-only ${BASE_COMMIT} | grep -i -v LinkDef)
RESULT_OUTPUT=$(git-clang-format-8 --commit ${BASE_COMMIT} --diff --binary $(which clang-format-8) ${COMMIT_FILES})
COMMIT_FILES=$(git diff --name-only "${BASE_COMMIT}" | grep -i -v LinkDef)
RESULT_OUTPUT=$(git clang-format --commit "${BASE_COMMIT}" --diff --binary "$(which clang-format)" -- "${COMMIT_FILES}")
if [ "$RESULT_OUTPUT" == "no modified files to format" ] || [ "$RESULT_OUTPUT" == "clang-format did not modify any files" ]; then
exit 0
else
git-clang-format-8 --commit $BASE_COMMIT --diff --binary $(which clang-format-8)
git clang-format --commit "$BASE_COMMIT" --diff --binary "$(which clang-format)"
echo "$RESULT_OUTPUT"
exit 1
fi
fi
2 changes: 1 addition & 1 deletion include/Common/SimpleLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SimpleLog
// Optionnaly, an automatic log rotation can be defined. Older files are renamed, appending .1, .2, .3, etc.
// \param logFilePath Path to log file. If NULL, using stdout/stderr. If /dev/null, messages are completely dropped.
// \param rotateMaxBytes Maximum file size, after which a new file is created. If zero, no limit.
// \param rotateMaxFiles Maximum number of files to keep (including the "current" file). If zero, no limit.
// \param rotateMaxFiles Maximum number of files to keep (including the "current" file). If zero, no limit. If one, a single file is created and cleared immediately, and messages are discarded after reaching rotateMaxBytes.
// \param rotateNow If non-zero, the file is immediately rotated (independently of its size), otherwise it is appended.
int setLogFile(const char* logFilePath = NULL,
unsigned long rotateMaxBytes = 0, unsigned int rotateMaxFiles = 0, unsigned int rotateNow = 0);
Expand Down
4 changes: 3 additions & 1 deletion include/Common/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ class Timer
/// Reset timer by adding timeout value to starting time value.
/// Usefull when called in loops, prevents loosing time elapsed after previous timeout.
/// (e.g.: to implement timeout every 1 second without drift in time)
void increment();
/// If ensureFuture is true, value is incremented until next occurence is in the future (and only if timeout has occured already),
/// to avoid possibly several successive immediate timeouts again when multiple timeout periods have been missed.
void increment(bool ensureFuture = false);

/// Check if time elapsed since timer reset (or last increment set) is bigger than timeout value set.
/// \return Returns 1 if timeout, 0 otherwise.
Expand Down
3 changes: 1 addition & 2 deletions src/Configuration.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void getValueSpecialization(void)
vString = f.getValue<std::string>(s);
}

//template void ConfigFile::getValue<float>(std::string, float&);
// template void ConfigFile::getValue<float>(std::string, float&);

// http://stackoverflow.com/questions/4586768/how-to-iterate-a-boost-property-tree
string indent(int level)
Expand Down Expand Up @@ -223,4 +223,3 @@ ConfigFileBrowser::Iterator ConfigFileBrowser::end()
{
return Iterator(this, ptPtr->end(), ptPtr->end());
}

1 change: 0 additions & 1 deletion src/Daemon.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,3 @@ Daemon::LoopStatus Daemon::doLoop()

// todo
// boost exceptions?

1 change: 0 additions & 1 deletion src/Exception.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,3 @@ const char* Exception::what() const noexcept

} // namespace Common
} // namespace AliceO2

1 change: 0 additions & 1 deletion src/Iommu.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@ bool isEnabled()
} // namespace Iommu
} // namespace Common
} // namespace AliceO2

3 changes: 1 addition & 2 deletions src/LineBuffer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,4 @@ int LineBuffer::getNextLine(std::string& nextLine)
return 0;
}

//void LineBuffer::appendString(const char *s) {}

// void LineBuffer::appendString(const char *s) {}
5 changes: 2 additions & 3 deletions src/MemPool.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void* MemPool::getPage()
int newIx = (lastPageIndexGet + 1 + i) % numberOfPages;
if (!pageIsUsed[newIx].test_and_set()) {
lastPageIndexGet = newIx;
//printf("getPage() scan => %d\n",j);
// printf("getPage() scan => %d\n",j);
return pageTable[newIx];
}
j++;
Expand All @@ -109,7 +109,7 @@ void MemPool::releasePage(void* pagePtr)
if (pagePtr == pageTable[pageIx]) {
pageIsUsed[pageIx].clear();
lastPageIndexRelease = pageIx;
//printf("realeasePage() scan => %d\n",j);
// printf("realeasePage() scan => %d\n",j);
return;
}
j++;
Expand All @@ -120,4 +120,3 @@ int MemPool::getPageSize()
{
return pageSize;
}

1 change: 0 additions & 1 deletion src/Program.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,3 @@ int Program::execute(int argc, char** argv)

} // namespace Common
} // namespace AliceO2

18 changes: 13 additions & 5 deletions src/SimpleLog.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ int SimpleLog::Impl::logV(SimpleLog::Impl::Severity s, const char* message, va_l
} else if (s == Severity::Warning) {
ix += snprintf(&buffer[ix], len - ix, "Warning - ");
} else {
//ix+=snprintf(&buffer[ix], len-ix, "");
// ix+=snprintf(&buffer[ix], len-ix, "");
}
}

Expand All @@ -144,6 +144,11 @@ int SimpleLog::Impl::logV(SimpleLog::Impl::Severity s, const char* message, va_l
if (fp != NULL) {
if ((ix + logFileSize > rotateMaxBytes) && (rotateMaxBytes > 0)) {
closeLogFile();
if (rotateMaxFiles == 1) {
// stop after first file
disableOutput = 1;
return -1;
}
rotate();
if (openLogFile())
return -1;
Expand Down Expand Up @@ -269,7 +274,11 @@ int SimpleLog::Impl::openLogFile()
if (logFilePath.length() == 0) {
return 0;
}
fp = fopen(logFilePath.c_str(), "a");
const char* mode = "a";
if (rotateMaxFiles == 1) {
mode = "w";
}
fp = fopen(logFilePath.c_str(), mode);
if (fp == NULL) {
return -1;
}
Expand Down Expand Up @@ -343,7 +352,7 @@ void SimpleLog::Impl::rotate()
rotateIx.push_back(std::stoi(postfix));
}
}
free(dp);
closedir(dp);
}

// sort indexes in order
Expand Down Expand Up @@ -371,7 +380,7 @@ void SimpleLog::Impl::rotate()
} else {
inFile = dirName + fileName + "." + std::to_string(oldIndex);
}
if ((newIndex > rotateMaxFiles) && (rotateMaxFiles != 0)) {
if ((newIndex >= rotateMaxFiles) && (rotateMaxFiles != 0)) {
// this file should be removed
unlink(inFile.c_str());
} else {
Expand Down Expand Up @@ -401,4 +410,3 @@ void SimpleLog::Impl::rotate()
}

/// \todo: thread to flush output every 1 second

1 change: 0 additions & 1 deletion src/SuffixNumber.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,3 @@ const std::vector<std::pair<std::string, const size_t>>& get()
} // namespace _SuffixNumberTable
} // namespace Common
} // namespace AliceO2

1 change: 0 additions & 1 deletion src/System.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,3 @@ void assertFileSystemType(const std::string& path, const std::set<std::string>&
} // namespace System
} // namespace Common
} // namespace AliceO2

1 change: 0 additions & 1 deletion src/Thread.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,3 @@ std::string Thread::getName()
{
return name;
}

13 changes: 10 additions & 3 deletions src/Timer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,17 @@ void Timer::reset(int timeout)
tmax = timeout / 1000000.0;
}

void Timer::increment()
void Timer::increment(bool ensureFuture)
{
t0 += std::chrono::microseconds((int)(tmax * 1000000.0));
if (ensureFuture) {
double tnext = getRemainingTime();
if ((tnext <= 0) && (tmax > 0)) {
int n = (int)(1 - (tnext / tmax));
t0 += std::chrono::microseconds((int)(n * tmax * 1000000.0));
}
} else {
t0 += std::chrono::microseconds((int)(tmax * 1000000.0));
}
}

int Timer::isTimeout()
Expand All @@ -64,4 +72,3 @@ double Timer::getRemainingTime()

} // namespace Common
} // namespace AliceO2

1 change: 0 additions & 1 deletion test/TestBasicThread.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ BOOST_AUTO_TEST_CASE(TestBasicThread)
thread.join();
BOOST_CHECK(number > 0);
}

1 change: 0 additions & 1 deletion test/TestIommu.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ BOOST_AUTO_TEST_CASE(TestIsEnabled)
{
BOOST_CHECK_NO_THROW(AliceO2::Common::Iommu::isEnabled());
}

1 change: 0 additions & 1 deletion test/TestSuffixNumber.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,3 @@ BOOST_AUTO_TEST_CASE(TestFloatingPoint)
sn.setNumber("-123");
BOOST_CHECK_EQUAL(sn.getNumber(), -123);
}

1 change: 0 additions & 1 deletion test/TestSuffixOption.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,3 @@ BOOST_AUTO_TEST_CASE(TestSuffixOption)
BOOST_CHECK(numberB.getNumber() == 123);
BOOST_CHECK(numberC == -1000.0);
}

1 change: 0 additions & 1 deletion test/TestSystem.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,3 @@ BOOST_AUTO_TEST_CASE(TestIsFileSystemTypeAnyOf)
BOOST_CHECK(System::isFileSystemTypeAnyOf("/sys", { "blahfs", "ext42" }).first == false);
#endif
}

1 change: 0 additions & 1 deletion test/testDaemon.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ int main(int argc, char* argv[])
Daemon d(argc, argv);
return d.run();
}

1 change: 0 additions & 1 deletion test/testFifo.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,3 @@ BOOST_AUTO_TEST_CASE(fifo_test)

printf("fifoSz=%d sum=%d\n", fifoSz, sum2);
}

8 changes: 5 additions & 3 deletions test/testSimpleLog.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
// helps to test e.g. command line parameters settings

#include <Common/SimpleLog.h>
#include <unistd.h>

int main()
{

SimpleLog theLog;
theLog.setLogFile("/tmp/test.log", 100, 4, 0);
theLog.info("test message");

for (int i = 0; i < 10; i++) {
theLog.info("test message %d", i);
}
// sleep(10);
return 0;
}

19 changes: 18 additions & 1 deletion test/testTimer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,23 @@ BOOST_AUTO_TEST_CASE(timer_test)
success = 1;
}

// test increment
printf("\nTest increment (ensureFuture=0)\n");
// this should blindly increase by fixed amount of time
t.reset(100000);
usleep(350000);
for (int i = 1; i <= 5; i++) {
printf("iteration %d : timeout = %d timeRemaining = %.2fs\n", i, (int)t.isTimeout(), t.getRemainingTime());
t.increment(0);
}
printf("\nTest increment (ensureFuture=1)\n");
// this should update timeout to next occurence, with respect to start and given period
t.reset(100000);
usleep(250000);
for (int i = 1; i <= 5; i++) {
printf("iteration %d : timeout = %d timeRemaining = %.2fs\n", i, (int)t.isTimeout(), t.getRemainingTime());
t.increment(1);
}

BOOST_CHECK_EQUAL(success, 1);
}

0 comments on commit c1192b7

Please sign in to comment.