Skip to content

Test: unit test io_input_test_para seems not appropriately programmed #3486

@kirk0830

Description

@kirk0830

Describe the bug

First see the function calls INPUT.init():

void Driver::init()
{
    ModuleBase::TITLE("Driver", "init");

    time_t time_start = std::time(NULL);
    ModuleBase::timer::start();

    // (1) read the input parameters.
    this->reading();
void Driver::reading(void)
{
    ModuleBase::timer::tick("Driver", "reading");

    // (1) read INPUT
    INPUT.Init(GlobalV::global_in_card);

There is no rank0 limited statement, so go into the function INPUT.init():

void Input::Init(const std::string& fn)
{
    ModuleBase::timer::tick("Input", "Init");
    this->Default();

    // only rank 0 reads the input file, check the code in this->Read()
    bool success = this->Read(fn);

    this->Default_2();

// xiaohui add 2015-09-16
#ifdef __MPI
    Parallel_Common::bcast_bool(input_error);
#endif
    if (input_error == 1)
    {
        ModuleBase::WARNING_QUIT("Input", "Bad parameter, please check the input parameters in file INPUT", 1);
    }

#ifdef __MPI
    Parallel_Common::bcast_bool(success);
#endif
    if (!success)
    {
        ModuleBase::WARNING_QUIT("Input::Init", "Error during readin parameters.", 1);
    }
#ifdef __MPI
    this->Bcast();
#endif

In Read() there is a statement that if present processor is not rank0, will directly return with false as return value. But what matters is, the Default() is called by EACH PROCESSOR instead of only rank0!
However, in unit test io_input_test_para:

#ifdef __MPI
TEST_F(InputParaTest, Bcast)
{
    if (GlobalV::MY_RANK == 0)
    {
        INPUT.Default(); /* hmmm... why there is not Default_2 here? and, seems Default is execute directly on each processor? */
    }
    INPUT.Bcast();
    EXPECT_EQ(INPUT.suffix, "ABACUS");

This will definitely cause segmentation fault: address not mapped error if:

  • some variables need to new address in Default, for example std::vector<>

However I also understand the way to design this unit test, it is because the Default() in reality is called before Read(), there would be parameters' values changed by user during Read().
My suggestion would be like:

  • Let each processor call Default().
  • Change values only on rank0
  • Bcast() and test

Expected behavior

No response

To Reproduce

No response

Environment

No response

Additional Context

No response

Task list for Issue attackers (only for developers)

  • Verify the issue is not a duplicate.
  • Describe the bug.
  • Steps to reproduce.
  • Expected behavior.
  • Error message.
  • Environment details.
  • Additional context.
  • Assign a priority level (low, medium, high, urgent).
  • Assign the issue to a team member.
  • Label the issue with relevant tags.
  • Identify possible related issues.
  • Create a unit test or automated test to reproduce the bug (if applicable).
  • Fix the bug.
  • Test the fix.
  • Update documentation (if necessary).
  • Close the issue and inform the reporter (if applicable).

Metadata

Metadata

Labels

BugsBugs that only solvable with sufficient knowledge of DFT

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions