I don't know if this is overly simplistic. But I can't imagine that it would be beyond the realm of possibility to require cops to be tested for homicidal tendencies and/or extreme racism before being allowed to interact with the public, whom they are hired to serve and protect.
We're looking for background checks before selling firearms to anyone who walks off the street. Why not require the same for cops who would be carrying firearms as well?
Is that so unreasonable?