It is in Book 21 that Odysseus gives these two loyal retainers a final test to ascertain the extent of their loyalty. He has already heard both of them protest their love of Odysseus, but at this stage in the text he is finally planning action and so gives them a final test of their loyalty so that he can know whether he is able to count on them or not. Up until this point, he has not revealed his true identity to them, so they are not aware of who they are talking to. Note what he asks them both:
Stockman, and you swineherd, I have something in my mind which I am in doubt whether to say or no; but I think I will say it. What manner of men would you be to stand by Odysseus, if some god should bring him back here all of a sudden? Say which you are disposed to do--to side with the suitors, or with Odysseus?
It is the favourable response Odysseus receives from both Eumaeus and Philoeteus that convinces him he is able to trust them and reveal his plans of how he is going to defeat the suitors. The way that the question is worded is particularly interesting, as it demands that both Eumaeus and Philoeteus take a definitive stance, either showing their loyalty to their master or to the suitors. This makes this test particularly appropriate in order for Odysseus to work out whether he is able to rely on them or not.