[RESEND PATCH v5 1/3] test_firmware: prevent race conditions by a correct implementation of locking