Skip to content

Added test cases related to database operations#11

Open
wu-zhao-min wants to merge 1 commit into
berkeleydb:masterfrom
wu-zhao-min:master
Open

Added test cases related to database operations#11
wu-zhao-min wants to merge 1 commit into
berkeleydb:masterfrom
wu-zhao-min:master

Conversation

@wu-zhao-min

Copy link
Copy Markdown

Added the processing of boundary conditions for the new database, the complete operation process of cursors, and the test cases for database statistics information.

@gburd gburd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the contribution, and for thinking about boundary/cursor/stat coverage — that kind of testing is welcome.

Unfortunately I can't merge this as-is: it won't compile. test/c/test_db185.c exercises the DB 1.85 compatibility API (it #includes db_185.h and dbp is the 1.85 DB). That handle is defined in src/dbinc/db_185.in and has only these methods:

typedef struct __db {
    DBTYPE type;
    int (*close)(struct __db *);
    int (*del)(const struct __db *, const DBT *, u_int);
    int (*get)(const struct __db *, const DBT *, DBT *, u_int);
    int (*put)(const struct __db *, DBT *, const DBT *, u_int);
    int (*seq)(const struct __db *, DBT *, DBT *, u_int);
    int (*sync)(const struct __db *, u_int);
    void *internal;
    int (*fd)(const struct __db *);
} DB;

So the new code can't build here:

  • dbp->cursor(...) and dbp->stat(...) — no such members on the 1.85 DB.
  • cursor->c_get/c_put/c_close (DBC), and constants DB_NEXT, DB_SET, DB_KEYFIRST, DB_NOTFOUND, DB_BTREE_STAT/DB_HASH_STAT/DB_RECNO_STAT — these are the modern API, not in db_185.h (the 1.85 API iterates with seq() + R_NEXT/R_FIRST and has no cursors or stat).

A couple of other issues to flag regardless:

  • char large_key[1024*1024] is a 1 MB stack array (stack overflow risk).
  • In test_db_cursor, sprintf((char *)key.data, ...) writes into the buffer returned by c_get, which is owned by Berkeley DB — that's a write into library-owned memory.

Two good ways forward:

  1. Best: add these cursor/stat/boundary tests against the modern API — e.g. a new test/c/ program (or extend one that uses db.h/DB_ENV), where DB->cursor, DBC->get, and DB->stat exist. That's where this coverage belongs.
  2. If you specifically want to extend the 1.85 path, use only get/put/del/seq/sync with the R_* flags, and keep buffers caller-owned.

Happy to review a revised version. Closing for changes, not merging.

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.

2 participants