Skip to content

Commit

Permalink
fix file read EOF OOM (#855)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan authored Jun 26, 2024
1 parent fc41581 commit 5c29c38
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 70 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/cmake_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- os: macos-13
dylib_path: /usr/local/lib/gcc/current
- os: macos-latest
dylib_path: /opt/homebrew/Cellar/gcc/14.1.0/lib/gcc/current
dylib_path: /opt/homebrew/Cellar/gcc/14.1.0_1/lib/gcc/current


steps:
Expand Down Expand Up @@ -82,9 +82,10 @@ jobs:
LIBRARY_PATH: ${{ matrix.dylib_path }} # used by clang, needed to find libquadmath - else link error
run: |
cmake $GITHUB_WORKSPACE -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DENABLE_SAMRAI_TESTS=OFF -DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DlowResourceTests=ON \
-DCMAKE_CXX_FLAGS="-DPHARE_DIAG_DOUBLES=1 -O2"
-DCMAKE_CXX_FLAGS="-DPHARE_DIAG_DOUBLES=1 "
- name: Build
working-directory: ${{runner.workspace}}/build
Expand All @@ -94,7 +95,5 @@ jobs:

- name: Test
working-directory: ${{runner.workspace}}/build
env:
CTEST_OUTPUT_ON_FAILURE: 1
run: ctest -j 2
run: ctest -j 2 --output-on-failure

10 changes: 4 additions & 6 deletions .github/workflows/cmake_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,15 @@ jobs:
set -ex
cmake $GITHUB_WORKSPACE
cd ${{runner.workspace}}/PHARE/subprojects/samrai && mkdir build && cd build
cmake .. -DENABLE_SAMRAI_TESTS=OFF -DCMAKE_BUILD_TYPE=Release
cmake .. -DENABLE_SAMRAI_TESTS=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo
make -j2 && sudo make install && cd ../.. && rm -rf samrai
cd ${{runner.workspace}}/build && rm -rf *
cmake $GITHUB_WORKSPACE -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON --fresh \
-DCMAKE_BUILD_TYPE=RelWithDebInfo -Dasan=OFF \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DlowResourceTests=ON -DdevMode=ON -Dbench=ON \
-DCMAKE_CXX_FLAGS="-DPHARE_DIAG_DOUBLES=1 -O2" -Dphare_configurator=ON
-DCMAKE_CXX_FLAGS="-DPHARE_DIAG_DOUBLES=1 " -Dphare_configurator=ON
- name: Build
working-directory: ${{runner.workspace}}/build
Expand All @@ -90,7 +91,4 @@ jobs:
- name: Test
working-directory: ${{runner.workspace}}/build
env:
CTEST_OUTPUT_ON_FAILURE: 1
run: ctest -j 2

run: ctest -j 2 --output-on-failure
10 changes: 2 additions & 8 deletions tests/core/data/gridlayout/gridlayout_allocsize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,12 @@ auto createAllocSizeParam()
throw std::runtime_error("Error cannot open " + fullName);
}

while (!inputFile.eof())
std::uint32_t iQuantity;
while (inputFile >> iQuantity)
{
std::uint32_t iQuantity;
std::array<std::uint32_t, GridLayoutImpl::dimension> numberCells;
std::array<double, GridLayoutImpl::dimension> dl;

inputFile >> iQuantity;


if (inputFile.eof() || inputFile.bad())
break;

writeToArray(inputFile, numberCells);
writeToArray(inputFile, dl);

Expand Down
14 changes: 3 additions & 11 deletions tests/core/data/gridlayout/gridlayout_cell_centered_coord.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,12 @@ auto createCellCenteringParam()
= createParam<GridLayoutImpl>(dl, nbCell, Point<double, GridLayoutImpl::dimension>{origin});


std::array<std::uint32_t, GridLayoutImpl::dimension> icell;
std::array<double, GridLayoutImpl::dimension> realPosition;

while (!value.eof())
while (writeToArray(value, icell) && writeToArray(value, realPosition))
{
std::array<std::uint32_t, GridLayoutImpl::dimension> icell;
std::array<double, GridLayoutImpl::dimension> realPosition;

if (value.eof() || value.bad())
break;

writeToArray(value, icell);
writeToArray(value, realPosition);

auto& param = params[0];

param.iCellForCentering.push_back(icell);
param.expectedPosition.push_back(realPosition);
}
Expand Down
26 changes: 5 additions & 21 deletions tests/core/data/gridlayout/gridlayout_field_centered_coord.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,15 @@ auto createFieldCenteringParam()

// constexpr std::uint32_t numberOfQuantities{14};

while (!summary.eof())
std::string quantity;
while (summary >> quantity)
{
std::string quantity;

std::array<std::uint32_t, GridLayoutImpl::dimension> nbCell;
std::array<double, GridLayoutImpl::dimension> dl;
std::array<std::uint32_t, GridLayoutImpl::dimension> iStart;
std::array<std::uint32_t, GridLayoutImpl::dimension> iEnd;
std::array<double, GridLayoutImpl::dimension> origin;

summary >> quantity;

if (summary.eof() || summary.bad())
break;

writeToArray(summary, nbCell);
writeToArray(summary, dl);
writeToArray(summary, iStart);
Expand All @@ -128,21 +122,11 @@ auto createFieldCenteringParam()
}


std::array<std::uint32_t, GridLayoutImpl::dimension> icell;
std::array<double, GridLayoutImpl::dimension> realPosition;

while (!value.eof())
while (value >> quantity && writeToArray(value, icell) && writeToArray(value, realPosition))
{
std::string quantity;
std::array<std::uint32_t, GridLayoutImpl::dimension> icell;
std::array<double, GridLayoutImpl::dimension> realPosition;

value >> quantity;

if (value.eof() || value.bad())
break;

writeToArray(value, icell);
writeToArray(value, realPosition);

auto quantityIt = namesToQuantity.find(quantity);
if (quantityIt != namesToQuantity.end())
{
Expand Down
9 changes: 2 additions & 7 deletions tests/core/data/gridlayout/gridlayout_indexing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,12 @@ auto createIndexingParam()
throw std::runtime_error("Error cannot open " + fullName);
}

while (!inputFile.eof())
std::uint32_t iQuantity;
while (inputFile >> iQuantity)
{
std::uint32_t iQuantity;
std::array<std::uint32_t, GridLayoutImpl::dimension> numberCells;
std::array<double, GridLayoutImpl::dimension> dl;

inputFile >> iQuantity;

if (inputFile.eof() || inputFile.bad())
break;

writeToArray(inputFile, numberCells);
writeToArray(inputFile, dl);

Expand Down
17 changes: 5 additions & 12 deletions tests/core/data/gridlayout/gridlayout_params.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,14 @@ auto createParam(std::array<double, GridLayoutImpl::dimension> const& dxdydz,


template<typename Array>
void writeToArray(std::ifstream& stream, Array& array)
bool writeToArray(std::ifstream& stream, Array& array)
{
std::size_t dim = array.size();
stream >> array[0];
if (dim > 1)
{
stream >> array[1];
}
if (dim > 2)
{
stream >> array[2];
}
for (std::size_t i = 0; i < dim; ++i)
if (!(stream >> array[i]))
return false;
return true;
}




#endif

0 comments on commit 5c29c38

Please sign in to comment.