nvswitch: add unit-test and fix potential segfault