tests: Add complex test with valgrind

There was only simple write and read test under valgrind. This commit
introduces a test which checks more use cases.