Skip to content

Declare the ORCA entry points in the unit test gpopt mock - #2254

Merged
tuhaihe merged 1 commit into
apache:mainfrom
my-ship-it:fix/unit-test-harness-pg16
Nov 7, 2026
Merged

tuhaihe merged 1 commit into
apache:mainfrom
my-ship-it:fix/unit-test-harness-pg16

Conversation

@my-ship-it

Copy link
Copy Markdown
Contributor

What does this PR do?

make check in any src/backend/*/test directory fails to build on main:

../../../../../src/test/unit/mock/gpopt_mock.c:10:1: error: no previous prototype for 'SerializeDXLPlan' [-Werror=missing-prototypes]
../../../../../src/test/unit/mock/gpopt_mock.c:17:1: error: no previous prototype for 'GPOPTOptimizedPlan' [-Werror=missing-prototypes]
...
make: *** [../../../../../src/Makefile.global:1058: ../../../../../src/test/unit/mock/gpopt_mock.o] Error 1

gpopt_mock.c defines seven ORCA entry points whose only declarations live in the ORCA C++ headers, which a C file cannot include. With the configured warning flags each definition is a -Wmissing-prototypes warning, and src/Makefile.custom turns it into an error. Because gpopt_mock.o is in every test program's MOCK_OBJS, every test directory stops there.

CI does not see this: top-level make unittest-check passes CFLAGS=-DUNITTEST on the command line, which replaces the configured warning flags. Running one directory's tests while writing them — the normal workflow — fails.

The fix declares the seven functions in the mock and gives InitGPOPT() / TerminateGPOPT() the (void) parameter lists their declarations have. Test harness only; nothing in the server changes.

This is the first of the independent fixes listed in discussion #2210.

Type of Change

  • Bug fix (non-breaking change)
  • New feature (non-breaking change)
  • Breaking change (fix or feature with breaking changes)
  • Documentation update

Test Plan

  • Unit tests added/updated
  • Integration tests added/updated
  • Passed make installcheck
  • Passed make -C src/test installcheck-cbdb-parallel

Built with --enable-cassert --enable-debug --enable-orca, GCC 12.2.1:

  • Before, on main: make -C src/backend/{utils/mmgr,access/transam,access/rmgrdesc}/test check all fail with the error above.
  • After: make -C src/backend/<dir>/test check builds and passes in 27 of the 30 test directories (210 tests). The other three — access/appendonly, access/gin, utils/fmgr — now get past the mock and stop at warnings in their own test files that only show up under the configured -O3 (-Werror=aggressive-loop-optimizations, -Werror=return-type, -Werror=suggest-attribute=format). Those are separate and not touched here.
  • CI-style make CFLAGS=-DUNITTEST -C src/backend unittest-check: still passes, 227 tests.

Impact

User-facing changes: None.

Dependencies: None.

Checklist

Additional Context

Discussion: #2210 (commit 1 of the series).

The discussion's description of this commit is out of date. Two of the three items it lists are already on main: quoting DLSUFFIX in mock.mk (452df84) and including fmgr.h in gpopt_mock.c (e938d9b). A third change, adding fmgr_last_builtin_oid / fmgr_builtin_oid_index to fmgrtab_mock.c, has been dropped: no test program links the real fmgr.o, so nothing references those symbols, and every test directory links without them.

@yjhjstz yjhjstz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@leborchuk leborchuk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

gpopt_mock.c defines SerializeDXLPlan(), GPOPTOptimizedPlan(),
LibraryVersion(), EnableXform(), DisableXform(), InitGPOPT() and
TerminateGPOPT(), but the only declarations of them are in the ORCA C++
headers, which a C file cannot include.  With the warning flags configure
picks, every definition is then a -Wmissing-prototypes warning, and
src/Makefile.custom makes it an error:

  gpopt_mock.c:10:1: error: no previous prototype for 'SerializeDXLPlan'
  [-Werror=missing-prototypes]

Since gpopt_mock.o is part of every test program's MOCK_OBJS, "make
check" in any src/backend/*/test directory stops there.

"make unittest-check" from the top of the tree does not see this,
because it passes CFLAGS=-DUNITTEST on the command line, which replaces
the configured warning flags altogether; so CI stays green while running
a single directory's tests, as one does while writing them, fails.

Declare the seven functions in the mock, and give InitGPOPT() and
TerminateGPOPT() the (void) parameter list the declarations have.
@tuhaihe
tuhaihe force-pushed the fix/unit-test-harness-pg16 branch from afc5997 to fd6f5e8 Compare November 7, 2026 00:35
@tuhaihe
tuhaihe enabled auto-merge (rebase) November 7, 2026 00:35
@tuhaihe
tuhaihe merged commit e8afb9a into apache:main Nov 7, 2026
121 of 122 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants